#                                               -*- Autoconf -*-
#                                               vim: ft=config :

dnl The contents of this file are subject to the MonetDB Public License
dnl Version 1.1 (the "License"); you may not use this file except in
dnl compliance with the License. You may obtain a copy of the License at
dnl http://www.monetdb.org/Legal/MonetDBLicense
dnl
dnl Software distributed under the License is distributed on an "AS IS"
dnl basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
dnl License for the specific language governing rights and limitations
dnl under the License.
dnl
dnl The Original Code is the MonetDB Database System.
dnl
dnl The Initial Developer of the Original Code is CWI.
dnl Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
dnl Copyright August 2008-2014 MonetDB B.V.
dnl All Rights Reserved.

# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.60)
AC_INIT([MonetDB], [11.19.7], [info@monetdb.org], [MonetDB])
AC_CONFIG_AUX_DIR([buildtools/conf])
AC_CONFIG_MACRO_DIR([buildtools/conf])
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
dnl use tar-ustar since we have long (longer than 99 characters) file names
AM_INIT_AUTOMAKE([tar-ustar no-dist-gzip dist-bzip2])
AC_CONFIG_SRCDIR([gdk/gdk.h])
AC_CONFIG_HEADERS([monetdb_config.h])
AC_SUBST([CONFIG_H], [monetdb_config.h])

HOST=[$target]
AC_DEFINE_UNQUOTED(HOST, "$HOST", [Host identifier])

if test x"$target_os" = xcygwin; then
	AC_DEFINE(WIN32, 1, [Define on Microsoft Windows (also under Cygwin)])
fi
AM_CONDITIONAL(NOT_WIN32, test x"$target_os" != xcygwin)
AM_CONDITIONAL(NATIVE_WIN32, false)

m4_ifndef([PKG_PROG_PKG_CONFIG],
  [m4_fatal([Could not locate the pkg-config autoconf
    macros. These are usually located in /usr/share/aclocal/pkg.m4.
    If your macros are in a different location, try setting the
    environment variable M4DIRS="-I/other/macro/dir" before running
    ./bootstrap or autoreconf again.])])

PKG_PROG_PKG_CONFIG

if test x"$PKG_CONFIG" = x ; then
	AC_MSG_ERROR([pkg-config is required to configure MonetDB])
fi

dnl VERSION_TO_NUMBER macro (copied from libxslt)
AC_DEFUN([MONETDB_VERSION_TO_NUMBER],
[`$1 | sed 's|[[_\-]][[a-zA-Z0-9]]*$||' | awk 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`])

# BUILD and SOURCE are *only* used for monetdb-config and RunMserver
# SOURCE is the absolute path name of the source directory
# (srcdir can be relative)

# The Q versions of various variables are used in places where \'s
# need to be escapes with an extra \.  Configure does not support \'s
# in path names, so there is no need to do anything special here
# except set the variables.  The command to set them in case we do
# need to escape the \'s is Qvar=`echo "$var" | sed 's/\\\\/\\\\\\\\/g'`
BUILD=[`pwd`]
AC_SUBST(BUILD)

SOURCE=[`(cd $srcdir && pwd)`]
AC_SUBST(SOURCE)

. $srcdir/libversions
AC_SUBST(GDK_VERSION)
AC_SUBST(MAPI_VERSION)
AC_SUBST(MONETDB5_VERSION)
AC_SUBST(STREAM_VERSION)

# if no --prefix option, we must set Qprefix to the default value
# the problem is that prefix is set very late in the process if it
# wasn't set by --prefix
if test "${prefix}x" = "NONEx"; then
	Qprefix="${ac_default_prefix}"
else
	Qprefix="${prefix}"
fi
Qprefix="`echo "$Qprefix" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(Qprefix)
# exec_prefix is created very late, so let make do the expansion
if test "${exec_prefix}x" = "NONEx"; then
	Qexec_prefix='${prefix}'
else
	Qexec_prefix="`echo "$exec_prefix" | sed 's/\\\\/\\\\\\\\/g'`"
fi
AC_SUBST(Qexec_prefix)

if test -f "$srcdir"/vertoo.data; then
	dnl  Developers compiling from Mercurial:
	dnl  default is --enable-strict --enable-assert --enable-debug --disable-optimize --enable-developer
	dft_strict=yes
	dft_assert=yes
	dft_debug=yes
	dft_optimize=no
	dft_developer=yes
else
	dnl  Users compiling from source tarball(s):
	dnl  default is --disable-strict --disable-assert --disable-debug --disable-optimize --disable-developer
	dft_strict=no
	dft_assert=no
	dft_debug=no
	dft_optimize=no
	dft_developer=no
fi

dnl small hack to get icc -no-gcc, done here because AC_PROG_CC shouldn't
dnl set GCC=yes if we use icc.
case "$CC" in
*icc*-no-gcc*) ;;
*icc*)
	dnl  Since version 8.0, ecc/ecpc are also called icc/icpc,
	dnl  and icc/icpc requires "-no-gcc" to avoid predefining
	dnl  __GNUC__, __GNUC_MINOR__, and __GNUC_PATCHLEVEL__ macros.
	icc_ver="`$CC -dumpversion 2>/dev/null`"
	case $icc_ver in
	8.*)	CC="$CC -no-gcc";;
	9.*)	CC="$CC -no-gcc";;
	10.*)	CC="$CC -no-gcc";;
	11.*)	CC="$CC -no-gcc";;
	*)	AC_MSG_WARN([icc ($CC) $icc_ver not handled, yet]);;
	esac
	;;
esac

AC_DEFINE(MONETDB_RELEASE, "Oct2014-SP1", [Release name or "unreleased"])

dft_gdk=yes
AC_ARG_ENABLE(gdk,
	AS_HELP_STRING([--enable-gdk],
		[enable support for GDK (default=yes)]),
	enable_gdk=$enableval,
	enable_gdk=$dft_gdk)

dft_monetdb5=yes
AC_ARG_ENABLE(monetdb5,
	AS_HELP_STRING([--enable-monetdb5],
		[enable support for MonetDB5 (default=yes)]),
	enable_monetdb5=$enableval,
	enable_monetdb5=$dft_monetdb5)
case "$enable_gdk-$enable_monetdb5" in
no-yes)
	AC_MSG_ERROR([MonetDB5 requires GDK.])
	;;
no-auto)
	enable_monetdb5=no
	disable_monetdb5="(MonetDB5 requires GDK.)"
	;;
esac

dft_rdf=no
AC_ARG_ENABLE(rdf,
	AS_HELP_STRING([--enable-rdf],
		[enable support for RDF [experimental/unsupported] (default=no)]),
	enable_rdf=$enableval,
	enable_rdf=$dft_rdf)

dft_datacell=no
AC_ARG_ENABLE(datacell,
	AS_HELP_STRING([--enable-datacell],
		[enable datacell stream components [experimental/unsupported] (default=no)]),
	enable_datacell=$enableval,
	enable_datacell=$dft_datacell)

dft_fits=auto
AC_ARG_ENABLE(fits,
	AS_HELP_STRING([--enable-fits],
		[enable support for FITS (default=auto)]),
	enable_fits=$enableval,
	enable_fits=$dft_fits)

dft_sql=yes
AC_ARG_ENABLE(sql,
	AS_HELP_STRING([--enable-sql],
		[enable support for MonetDB/SQL (default=yes)]),
	enable_sql=$enableval,
	enable_sql=$dft_sql)
case "$enable_monetdb5-$enable_sql" in
no-yes)
	AC_MSG_ERROR([MonetDB/SQL requires MonetDB5.])
	;;
no-auto)
	enable_sql=no
	disable_sql="(MonetDB/SQL requires MonetDB5.)"
	;;
esac

dft_geom=auto
AC_ARG_ENABLE(geom,
	AS_HELP_STRING([--enable-geom],
		[enable support for geom module (default=auto)]),
	enable_geom=$enableval,
	enable_geom=$dft_geom)
case "$enable_monetdb5-$enable_geom" in
no-yes)
	AC_MSG_ERROR([geom module requires MonetDB5])
	;;
no-auto)
	enable_geom=no
	disable_geom="(geom module requires MonetDB5)"
	;;
esac

dft_jsonstore=no
AC_ARG_ENABLE(jsonstore,
	AS_HELP_STRING([--enable-jsonstore],
		[enable support for MonetDB/jsonstore (default=no)]),
	enable_jsonstore=$enableval,
	enable_jsonstore=$dft_jsonstore)

dft_microhttpd=$enable_jsonstore
AC_ARG_ENABLE(microhttpd,
	AS_HELP_STRING([--enable-microhttpd],
		[enable support for the builtin MircoHTTPD daemon (default: implied by --enable-jsonstore)]),
	enable_microhttpd=$enableval,
	enable_microhttpd=$dft_microhttpd)

case "$enable_jsonstore-$enable_microhttpd" in
yes-no)
	AC_MSG_ERROR([jsonstore require microhttpd])
	;;
auto-no)
	enable_jsonstore=no
	disable_jsonstore="(jsonstore required microhttpd)"
	;;
esac

dft_gsl=auto
AC_ARG_ENABLE(gsl,
	AS_HELP_STRING([--enable-gsl],
		[enable support for GSL (default=auto)]),
	enable_gsl=$enableval,
	enable_gsl=$dft_gsl)

dft_rintegration=auto
AC_ARG_ENABLE(rintegration,
	AS_HELP_STRING([--enable-rintegration],
		[enable support for R integration into MonetDB (default=auto)]),
	enable_rintegration=$enableval,
	enable_rintegration=$dft_rintegration)

dft_odbc=auto
AC_ARG_ENABLE(odbc,
	AS_HELP_STRING([--enable-odbc],
		[compile the MonetDB ODBC driver (default=auto)]),
	enable_odbc=$enableval,
	enable_odbc=$dft_odbc)

dft_testing=auto
AC_ARG_ENABLE(testing,
	AS_HELP_STRING([--enable-testing],
		[enable support for testing (default=auto)]),
	enable_testing=$enableval,
	enable_testing=$dft_testing)

AC_ARG_ENABLE(developer,
	AS_HELP_STRING([--enable-developer],
		[enable support for MonetDB development (default=yes for development sources)]),
	enable_developer=$enableval,
	enable_developer=$dft_developer)

dnl The console is a direct client hooked onto the kernel with full
dnl administrative privileges, bypassing any security checks.  It is
dnl handy only during development.
dnl We simply can't disable it for now because Testing gets hopelessly
dnl upset about it, but we can offer to the user to disable it for
dnl increased security.
use_console=yes
AC_ARG_ENABLE(console,
	AS_HELP_STRING([--enable-console],
		[enables direct console on the server (involves security risks) (default=yes)]),
	use_console="$enableval")
if test x$use_console = xyes ; then
	AC_DEFINE([HAVE_CONSOLE], 1, [If the console should be used])
fi

dft_jdbc=auto
AC_ARG_ENABLE(jdbc,
	AS_HELP_STRING([--enable-jdbc], [build the MonetDB JDBC driver]),
	enable_jdbc="$enableval",
	enable_jdbc=$dft_jdbc)
case $enable_jdbc in
	yes|auto) enable_jdbc=$enable_jdbc;;
	*) enable_jdbc=no;;
esac

dft_control=auto
AC_ARG_ENABLE(merocontrol,
	AS_HELP_STRING([--enable-merocontrol], [build the Merovingian control driver]),
	enable_control="$enableval",
	enable_control=$dft_control)
case $enable_control in
	yes|auto) enable_control=$enable_control;;
	*) enable_control=no;;
esac

AC_ARG_ENABLE(static-analysis,
	AS_HELP_STRING([--enable-static-analysis], [configure for static code analysis (use only if you know what you are doing)]),
	AC_DEFINE([STATIC_CODE_ANALYSIS], 1, [compiling for static code analysis]))

dnl RIPEMD160 is patent free, academic and European, but unfortunately
dnl can't use it by default, as that would exclude JDBC usage (Java
dnl doesn't natively support RIPEMD160).
MONETDB5_PASSWDHASH="SHA512"
AC_ARG_WITH(password-backend,
	AS_HELP_STRING([--with-password-backend=HASHALG],
		[password hash algorithm, one of MD5, SHA1, RIPEMD160, SHA224, SHA256, SHA384, SHA512, defaults to SHA512]),
	password_backend="$withval")
case "$password_backend" in
yes|no|auto|"")
	;;
MD5|SHA1|RIPEMD160|SHA224|SHA256|SHA384|SHA512)
	MONETDB5_PASSWDHASH="$password_backend"
	;;
*)
	AC_MSG_ERROR(['$password_backend' invalid, choose one of MD5, SHA1, RIPEMD160, SHA224, SHA256, SHA384, SHA512])
	;;
esac
AC_DEFINE_UNQUOTED([MONETDB5_PASSWDHASH], "$MONETDB5_PASSWDHASH", [The used password hash algorithm])
AC_SUBST([MONETDB5_PASSWDHASH])

AC_DISABLE_STATIC
AC_ENABLE_SHARED
AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling = xyes)

dnl logs usually end up in /var/log
logdir='${localstatedir}/log/monetdb'
AC_ARG_WITH(logdir,
	AS_HELP_STRING([--with-logdir=DIR],
		[Where to put log files (LOCALSTATEDIR/log/monetdb/)]),
	[case "$withval" in
		yes|no|auto)
			AC_MSG_WARN([--with-logdir called without argument - will use default])
		;;
		*)
			logdir="$withval"
		;;
	esac]
)

dnl pidfiles usually end up in /var/run
rundir='${localstatedir}/run/monetdb'
AC_ARG_WITH(rundir,
	AS_HELP_STRING([--with-rundir=DIR],
		[Where to put pid files (LOCALSTATEDIR/run/monetdb/)]),
	[case "$withval" in
		yes|no|auto)
			AC_MSG_WARN([--with-rundir called without argument - will use default])
		;;
		*)
			rundir="$withval"
		;;
	esac]
)


dnl     checks for programs
AC_LANG([C])

# autoconf-2.60: enable extensions on systems that normally disable them
AC_USE_SYSTEM_EXTENSIONS()
# enable 64-bits file offsets, check this early, since it breaks other
# stuff (in particular on Solaris), which we do not want to detect as
# usable below in that case
AC_SYS_LARGEFILE

AC_PROG_CPP()
dnl check for compiler (also set GCC (yes/no)).
AC_PROG_CC()

dnl What do we need to get the msg_control and msg_controllen fields on
dnl struct msg (filedescriptor passing)?  In the future this could be a
dnl check to see if we can find it, such that we can disable it compile
dnl time if absent.  It looks however, as if it's available everywhere
dnl we try where UNIX domain sockets also exist.  So we go by the
dnl following simple implementation for now.
case $host in
	*-solaris*)
		dnl Solaris needs this to get msg_control and msg_controllen
		dnl it disables, however, the availability of madvise, which is
		dnl in use use by GDK, so we cannot just AC_DEFINE this, but
		dnl rather have to enable it where it is necessary
		MSGCONTROL_FLAGS="-D_XOPEN_SOURCE=500"
		AC_SUBST(MSGCONTROL_FLAGS)
	;;
esac

dnl  (try to) determine compiler type (gcc, icc, clang) (and version)
dnl  independent of call ($CC) and result of AC_PROG_CC() ($GCC)
dnl  (e.g., on OSX, Apple pretends its clang were gcc)
AC_MSG_CHECKING(compiler type & version)
gcc_ver=""
icc_ver=""
CC_ver=""
CC_version="`$CC --version 2>&1`"
case "$CC_version" in
*\(GCC\)*|*Copyright\ \(C\)\ *\ Free\ Software\ Foundation,\ Inc.*)
	gcc_ver="`$CC -dumpversion 2>/dev/null`"
	CC_ver="gcc-$gcc_ver"
	;;
*\(ICC\)*|*Copyright\ \(C\)\ *\ Intel\ Corporation.\ \ All\ rights\ reserved.*)
	icc_ver="`$CC -dumpversion 2>/dev/null`"
	CC_ver="icc-$icc_ver"
	;;
*clang*)
	dnl  `clang -dumpversion` reports the original/old gcc version it is based on
	gcc_ver="`$CC -v 2>&1 | grep -w '[[Vv]]ersion [[0-9]]\+\.[[0-9]]\+' | sed 's|^.*[[Vv]]ersion \([[0-9]][[0-9]]*\(\.[[0-9]][[0-9]]*\)\(\.[[0-9]][[0-9]]*\)*\).*$|\1|'`"
	CC_ver="clang-$gcc_ver"
	;;
*)
	CC_V="`$CC -V 2>&1`"
	case "$CC_V" in
	*Sun\ Ceres\ C\ *|*Sun\ C\ *)
		# developer/sunstudioexpress and
		# developer/sunstudio12u1 respectively
		CC_ver="suncc-`echo "$CC_version" | sed -n 's/.*Sun Ceres C \(.*\) SunOS.*/\1/p;s/.*Sun C \(.*\) SunOS.*/\1/p'`"
		CC_version="$CC_V"
		;;
	*)
		AC_MSG_WARN([compiler not recognized:
`$CC --version` says
$CC_version
`$CC -V` says
$CC_V
	])
		;;
	esac
	;;
esac
AC_MSG_RESULT($CC_ver)

dnl  sanity/consistency check
case "$GCC!$CC!$CC_ver" in
yes!*clang*!clang-*)	;;
yes!*gcc*!clang-*)	;;
yes!*gcc*!gcc-*)	;;
!*icc*!icc-*)	;;
*!*!suncc-*)	;;
*)	AC_MSG_WARN([compiler potentially not (correctly) recognized:
GCC=$GCC
CC=$CC
CC_ver=$CC_ver
CC_version=
$CC_version
	]);;
esac

AC_ARG_WITH(bits,
	AS_HELP_STRING([--with-bits=BITS],
		[obsolete: specify by setting CC in the environment]),
	AC_MSG_ERROR([argument --with-bits is obsolete: specify by setting CC in the environment]))

AC_CHECK_SIZEOF(long)
native_bits=`expr $ac_cv_sizeof_long \* 8`
bits=$native_bits
AC_ARG_ENABLE(bits,
	AS_HELP_STRING([--enable-bits],
		[obsolete: specify by setting CC in the environment]),
	if test x$enableval = x$bits; then
		AC_MSG_WARN([argument --enable-bits is obsolete: specify by setting CC in the environment])
	else
		AC_MSG_ERROR([argument --enable-bits is obsolete: specify by setting CC in the environment])
	fi)
AC_SUBST(bits)
AM_CONDITIONAL(BITS32, test x"$bits" = x32)
AM_CONDITIONAL(BITS64, test x"$bits" = x64)

oids=$bits
AC_ARG_ENABLE(oid32,
	AS_HELP_STRING([--enable-oid32],
		[use 32 bits for OIDs on a 64-bit architecture]),
	enable_oid32=$enableval,
	enable_oid32=no)
AC_MSG_CHECKING(size of OIDs)
case $bits-$enable_oid32 in
64-yes)	AC_DEFINE(MONET_OID32, 1, [Define if the oid type should use 32 bits on a 64-bit architecture])
	oids=32
	;;
esac
AC_SUBST(oids)
AC_MSG_RESULT($oids bits)

AC_C_BIGENDIAN()

LINUX_DIST=''
case "$host_os" in
    linux*)
	dnl  Please keep this aligned / in sync with testing/Mtest.py.in !
	AC_MSG_CHECKING(which Linux distribution we're using)
	if test -s /etc/os-release; then
		# this is the new way of getting release information
		# works for Fedora >= 17, Ubuntu >= 12.04 (Precise Pangolin)
		LINUX_DIST=`source /etc/os-release; echo ${ID}:${VERSION_ID}`
	elif test -s /etc/fedora-release ; then
		LINUX_DIST="`cat /etc/fedora-release | head -n1 \
			| sed 's|^.*\(Fedora\).* release \([[0-9]][[^ \n]]*\)\( .*\)*$|\1:\2|'`" 
	elif test -s /etc/centos-release ; then
		LINUX_DIST="`cat /etc/centos-release | head -n1 \
			| sed 's|^\(CentOS\).* release \([[0-9]][[^ \n]]*\)\( .*\)*$|\1:\2|'`"
	elif test -s /etc/yellowdog-release ; then
		LINUX_DIST="`cat /etc/yellowdog-release | head -n1 \
			| sed 's|^\(Yellow\) Dog Linux release \([[0-9]][[^ \n]]*\)\( .*\)*$|\1:\2|'`"
	elif test -s /etc/redhat-release ; then
		LINUX_DIST="`cat /etc/redhat-release | head -n1 \
			| sed 's|^.*\(Red\) \(Hat\).* Linux *\([[A-Z]]*\) release \([[0-9]][[^ \n]]*\)\( .*\)*$|\1\2:\4\3|' \
			| sed 's|^Red Hat Enterprise Linux \([[AW]]S\) release \([[0-9]][[^ \n]]*\)\( .*\)*$|RHEL:\2\1|' \
			| sed 's|^\(CentOS\).* release \([[0-9]][[^ \n]]*\)\( .*\)*$|\1:\2|' \
			| sed 's|^\(Scientific\) Linux.* release \([[0-9]][[^ \n]]*\)\( .*\)*$|\1:\2|'`" 
	elif test -s /etc/SuSE-release ; then
		LINUX_DIST="`cat /etc/SuSE-release   | head -n1 \
			| sed 's|^.*\(S[[Uu]]SE\) LINUX Enterprise \([[SD]]\)[[ervsktop]]* \([[0-9]][[^ \n]]*\)\( .*\)*$|\1:\3E\2|' \
			| sed 's|^S[[Uu]]SE LINUX Enterprise \([[SD]]\)[[ervsktop]]* \([[0-9]][[^ \n]]*\)\( .*\)*$|SLE\1:\2|' \
			| sed 's|^.*\(S[[Uu]]SE\) [[Ll]][[Ii]][[Nn]][[Uu]][[Xx]].* \([[0-9]][[^ \n]]*\)\( .*\)*$|\1:\2|' \
			| sed 's|^open\(S[[Uu]]SE\) \([[0-9]][[^ \n]]*\)\( .*\)*$|\1:\2|'`"
	elif test -s /etc/gentoo-release ; then
		LINUX_DIST="`cat /etc/gentoo-release | head -n1 \
			| sed 's|^.*\(Gentoo\) Base System.* [[versionrelease]]* \([[0-9]][[^ \n]]*\)\( .*\)*$|\1:\2|'`" 
	elif test -s /etc/lsb-release ; then
		LINUX_DIST="`grep '^DISTRIB_ID=' /etc/lsb-release | cut -d'=' -f2`:`grep '^DISTRIB_RELEASE=' /etc/lsb-release | cut -d'=' -f2`"
	elif test -s /etc/debian_version ; then
		LINUX_DIST="Debian:`cat /etc/debian_version | head -n1`"
	else
		LINUX_DIST="`uname -s`:`uname -r | sed 's|^\([[0-9\.]]*\)\([[^0-9\.]].*\)$|\1|'`"
	fi
	LINUX_DIST="`echo "$LINUX_DIST" | sed 's|:||'`"
	AC_MSG_RESULT($LINUX_DIST)
	;;
esac
AC_SUBST(LINUX_DIST)

AC_DEFUN([MCHECK_ADD_FLAG],
[
	cache_var=AS_TR_SH([m_cv_cc_has_$1])
	AC_CACHE_CHECK([whether ${CC} supports $1], [${cache_var}],
	[
	SAVE_FLAGS="${CFLAGS}"
	# compile a small program that has enough challenges to trigger
	# the compiler to actually do something, such that it needs to
	# actually look at the flags given
	CFLAGS="${SAVE_FLAGS} ${X_CFLAGS} $1"
	dnl do not use AC_LANG_PROGRAM here, because it generates a program
	dnl with "int main() {" function, which triggers
	dnl old-style-definition warnings
	AC_LINK_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif

#if -_LARGEFILE64_SOURCE - -1 == 1
#include <stdio.h>
#endif
int main(int argc, char **av) {
	char buf[24];
	double d = atof("4.2");
	if (argc == 0 || strchr(av[0], av[0][0]) != NULL)
		snprintf(buf, sizeof(buf), "%f", d);
	return 0;
}
					  ]])],
					  [eval ${cache_var}=yes],
					  [eval ${cache_var}=no])
	CFLAGS="${SAVE_FLAGS}"
	])
	eval "test \"x\$${cache_var}\" = xyes && X_CFLAGS=\"${X_CFLAGS} $1\""
])

dnl --enable-strict
AC_ARG_ENABLE(strict,
	AS_HELP_STRING([--enable-strict],
		[enable strict compiler flags (default=yes for development sources)]),
	enable_strict=$enableval,
	enable_strict=$dft_strict)
dnl  Set compiler switches.
dnl  The idea/goal is to be as strict as possible, i.e., enable preferably
dnl  *all* warnings and make them errors. This should help keep the code
dnl  as clean and portable as possible.
dnl  It turned out, though, that this, especially turning all warnings into 
dnl  errors, is a bit too ambitious for configure/autoconf. Hence, we set
dnl  all flags that enable specific warnings and those that make the
dnl  compiler die on them (-Werror) in X_CFLAGS, which are added to the
dnl  standard CFLAGS once configure/autoconf are done with their job,
dnl  i.e., at the end of this configure[.ag] script.
dnl  Only GNU (gcc) and Intel ([ie]cc/[ie]cpc on Linux) are done so far.
: ${X_CFLAGS=} # initialize to empty if not set
if test "x$enable_strict" = xyes; then
case "$GCC-$CC-$host_os" in
yes-*-*)
	MCHECK_ADD_FLAG([-Werror])  dnl keep this one first
	MCHECK_ADD_FLAG([-Wall])
	MCHECK_ADD_FLAG([-Wextra])
	MCHECK_ADD_FLAG([-W])
	MCHECK_ADD_FLAG([-Werror-implicit-function-declaration])

	MCHECK_ADD_FLAG([-Wpointer-arith])
	MCHECK_ADD_FLAG([-Wdeclaration-after-statement])
	MCHECK_ADD_FLAG([-Wundef])
	MCHECK_ADD_FLAG([-Wformat=2])
	MCHECK_ADD_FLAG([-Wno-format-nonliteral])
	MCHECK_ADD_FLAG([-Winit-self])
	MCHECK_ADD_FLAG([-Winvalid-pch])
	MCHECK_ADD_FLAG([-Wmissing-declarations])
	MCHECK_ADD_FLAG([-Wmissing-format-attribute])
	MCHECK_ADD_FLAG([-Wmissing-prototypes])
	MCHECK_ADD_FLAG([-Wold-style-definition])
	MCHECK_ADD_FLAG([-Wpacked])
	MCHECK_ADD_FLAG([-Wunknown-pragmas])
	MCHECK_ADD_FLAG([-Wvariadic-macros])
	MCHECK_ADD_FLAG([-fstack-protector-all])
	MCHECK_ADD_FLAG([-Wstack-protector])
	MCHECK_ADD_FLAG([-Wpacked-bitfield-compat])
	MCHECK_ADD_FLAG([-Wsync-nand])
	MCHECK_ADD_FLAG([-Wjump-misses-init])
	MCHECK_ADD_FLAG([-Wmissing-include-dirs])
	MCHECK_ADD_FLAG([-Wlogical-op])

	dnl  With clang 2.8, 3.3, 5.0 (no other tested) and gcc < 4.5
	dnl  (tested 3.4.6, 4.2.1, 4.3.2, 4.4.4, 4.4.5, 4.5.1, 4.5.2),
	dnl  "-Wunreachable-code" triggers numerous "will never be
	dnl  executed" (at least) in our stream code, mostly (if
	dnl  not all) false positives, though, as well as in
	dnl  YACC/BISON-generated code; thus, we do not use
	dnl  "-Wunreachable-code" with clang and gcc < 4.5 .
	dnl  At the same time, Apple deprecated OpenSSL in favour of
	dnl  their own CommonCrypto API.  We don't mind about that.
	case "$CC_ver" in
	clang-*|gcc-[[0-3]].*|gcc-4.[[0-4]].*)
		MCHECK_ADD_FLAG([-Wno-deprecated-declarations])
		;;
	*)
		MCHECK_ADD_FLAG([-Wunreachable-code])
		;;
	esac

	dnl  Our code is not (yet?) up to these:
	dnl MCHECK_ADD_FLAG([-pedantic-errors])
	dnl MCHECK_ADD_FLAG([-Wno-long-long])
	dnl MCHECK_ADD_FLAG([-Waggregate-return])
	dnl MCHECK_ADD_FLAG([-Wbad-function-cast])
	dnl MCHECK_ADD_FLAG([-Wcast-qual])
	dnl MCHECK_ADD_FLAG([-Wconversion])
	dnl MCHECK_ADD_FLAG([-Wdisabled-optimization])
	dnl MCHECK_ADD_FLAG([-Wfloat-equal])
	dnl MCHECK_ADD_FLAG([-Winline])
	dnl MCHECK_ADD_FLAG([-Wmissing-noreturn])
	dnl MCHECK_ADD_FLAG([-Wnested-externs])
	dnl MCHECK_ADD_FLAG([-Wpadded])
	dnl MCHECK_ADD_FLAG([-Wredundant-decls])
	dnl MCHECK_ADD_FLAG([-Wshadow])
	dnl MCHECK_ADD_FLAG([-Wstrict-prototypes])
	dnl MCHECK_ADD_FLAG([-Wswitch-default])
	dnl MCHECK_ADD_FLAG([-Wswitch-enum])
	dnl MCHECK_ADD_FLAG([-Wtraditional])
	dnl MCHECK_ADD_FLAG([-Wtraditional-conversion])
	dnl MCHECK_ADD_FLAG([-Wwrite-strings])
	dnl MCHECK_ADD_FLAG([-Wc++-compat])
	dnl MCHECK_ADD_FLAG([-Woverlength-strings])
	dnl MCHECK_ADD_FLAG([-Wsign-conversion])
	dnl MCHECK_ADD_FLAG([-Wstrict-overflow=5])
	dnl MCHECK_ADD_FLAG([-Wvla])
	dnl MCHECK_ADD_FLAG([-Wunsuffixed-float-constants])
	;;
-*icc*-linux*|-*ecc*-linux*)
	dnl  Intel ([ie]cc/[ie]cpc on Linux)
	LDFLAGS="$LDFLAGS -i_dynamic"
	dnl  Let warning #140 "too many arguments in function call"
	dnl  become an error to make configure tests work properly.
	CFLAGS="$CFLAGS -we140"
	dnl  Let warning #147 "declaration is incompatible"
	dnl  become an error to make configure tests work properly.
	CFLAGS="$CFLAGS -we147"
	dnl  Check for PIC does not work with Version 8.1, unless we disable
	dnl  remark #1418: external definition with no prior declaration ... !?
	case $icc_ver in
	8.1*)	CFLAGS="$CFLAGS -wd1418" ;;
	9.*)	CFLAGS="$CFLAGS -wd1418" ;;
	10.*)	CFLAGS="$CFLAGS -wd1418" ;;
	11.*)	CFLAGS="$CFLAGS -wd1418" ;;
	*)	;;
	esac
	dnl  Version 8.* doesn't find sigset_t when -ansi is set... !?
	case $icc_ver in
	8.*)	;;
	9.*)	;;
	10.*)	;;
	11.*)	;;
	*)	CFLAGS="$CFLAGS -ansi";;
	esac
	dnl  Be picky; "-Werror" seems to be too rigid for autoconf...
	CFLAGS="$CFLAGS -Wall -w2 -Wcheck"
	dnl  Be rigid; MonetDB code is supposed to adhere to this... ;-)
	dnl  Let the follows remarks and warning become errors:
	dnl  #266: "function declared implicitly"
	dnl  #181: "argument is incompatible with corresponding format string conversion"
	dnl  #810: "conversion from "." to "." may lose significant bits"
	dnl  #111: "statement is unreachable"
	dnl  #271: "trailing comma is nonstandard"
	dnl  #593: "variable "." was set but never used"
	X_CFLAGS="$X_CFLAGS -we266,181,810,271,593"
	X_CFLAGS="$X_CFLAGS -Werror -Werror-all"
	dnl  ... however, some things aren't solved, yet:
	dnl  (for the time being,) we need to disable some warnings (making them remarks doesn't seem to work with -Werror):
	X_CFLAGS="$X_CFLAGS -wd1418,1419,981,193,1357"
	dnl ICC 11 warns about non-pointer conversion from "<type>" to
	dnl "<smaller>" may lose significant bits, it does however, also for
	dnl constants like short s = 1234, which is too much
	case $icc_ver in
	11.*)       X_CFLAGS="$X_CFLAGS,2259" ;;
	esac
	case $icc_ver in
	8.[[1-9]]*)	X_CFLAGS="$X_CFLAGS,1572" ;;
	9.[[1-9]]*)	X_CFLAGS="$X_CFLAGS,1572,1599" ;;
	10.*)		X_CFLAGS="$X_CFLAGS,1572,1599" ;;
	11.*)		X_CFLAGS="$X_CFLAGS,1572,1599" ;;
	esac
	dnl  #1418: external definition with no prior declaration
	dnl  #1419: external declaration in primary source file
	dnl  # 981: operands are evaluated in unspecified order
	dnl  # 193: zero used for undefined preprocessing identifier
	dnl  #1357: optimization disabled due to excessive resource requirements; contact Intel Premier Support for assistance
	dnl  #1572: floating-point equality and inequality comparisons are unreliable
	dnl  #1599: declaration hides variable 
	dnl  #2259: non-pointer conversion from "." to "." may lose significant bits
	;;
esac
fi
AC_SUBST(CFLAGS)
AC_SUBST(X_CFLAGS)

dnl icc needs -fPIC (but the current autoconf still uses -KPIC)
case "$GCC-$CC-$host_os" in
-*icc*-linux*|-*ecc*-linux*)
	case $icc_ver in
	10.*) 	CC="$CC -fPIC"		 ;;
	11.*) 	CC="$CC -fPIC"		 ;;
	*)	;;
	esac
esac

dnl some dirty hacks
THREAD_SAVE_FLAGS="\$(thread_safe_flag_spec) -D_REENTRANT"
# only needed in monet
case "$host_os" in
solaris*)
    case "$GCC" in
      yes) ;;
      *) 
        THREAD_SAVE_FLAGS="$THREAD_SAVE_FLAGS -mt"
        ;;
    esac
    ;;
aix*)
    THREAD_SAVE_FLAGS="$THREAD_SAVE_FLAGS -D_THREAD_SAFE"
    case "$GCC" in
      yes)
        THREAD_SAVE_FLAGS="$THREAD_SAVE_FLAGS -mthreads"
        ;;
      *)
        THREAD_SAVE_FLAGS="$THREAD_SAVE_FLAGS -qthreaded"
        ;;
    esac
    ;;
esac
AC_SUBST(thread_safe_flag_spec)
AC_SUBST(THREAD_SAVE_FLAGS)

AC_PROG_INSTALL
AC_LIBTOOL_DLOPEN
AC_LIBTOOL_WIN32_DLL
AC_LIBTOOL_SETUP
AC_PROG_LIBTOOL
AM_PROG_LIBTOOL

READLINK='readlink -f'
AC_MSG_CHECKING([for $READLINK])
$READLINK /tmp >/dev/null 2>&1
if test $? -ne 0; then
	READLINK=echo
fi
AC_MSG_RESULT($READLINK)
AC_SUBST(READLINK)

translatepath=echo
anttranslatepath=$READLINK

dnl --with-translatepath
AC_ARG_WITH(translatepath,
	AS_HELP_STRING([--with-translatepath=PROG],
		[program to translate paths from configure-time format to execute-time format.  Take care that this program can be given paths like ${prefix}/etc which should be translated carefully.]),
	[translatepath="$withval"
	 anttranslatepath="$withval"],
	[if test x$cross_compiling = xyes; then
		AC_MSG_WARN([Cross compiling, but no --with-translatepath option given])
	fi])
AC_SUBST(translatepath)

dnl --with-anttranslatepath
AC_ARG_WITH(anttranslatepath,
	AS_HELP_STRING([--with-anttranslatepath=PROG],
		[program to translate paths from configure-time format to a format that can be given to the ant program (default: 'readlink -f' or value for --with-translatepath)]),
	anttranslatepath="$withval")
AC_SUBST(anttranslatepath)

AC_ARG_ENABLE(debug,
	AS_HELP_STRING([--enable-debug],
		[enable full debugging (default=yes for development sources)]),
	enable_debug=$enableval,
	enable_debug=def_$dft_debug)

AC_ARG_ENABLE(assert,
	AS_HELP_STRING([--enable-assert],
		[enable assertions in the code (default=yes for development sources)]),
	enable_assert=$enableval,
	enable_assert=def_$dft_assert)

AC_ARG_ENABLE(optimize,
	AS_HELP_STRING([--enable-optimize],
		[enable extra optimization (default=no)]),
	enable_optimize=$enableval,
	enable_optimize=def_$dft_optimize)

need_profile=no
dft_profile=$need_profile
AC_ARG_ENABLE(profile,
	AS_HELP_STRING([--enable-profile], [enable profiling (default=no)]),
	enable_profile=$enableval,
	enable_profile=def_$dft_profile)

need_instrument=no
dft_instrument=$need_instrument
AC_ARG_ENABLE(instrument,
	AS_HELP_STRING([--enable-instrument],
		[enable instrument (default=no)]),
	enable_instrument=$enableval,
	enable_instrument=def_$dft_instrument)

dnl check whether no (explictly chosen) mutual exclusive combinations
dnl were made, compatability matrix:
dnl                 deb  ass  opt  pro  ins
dnl   debug          \    C    X    C    C
dnl   assert         C    \    C    C    C
dnl   optimize       X    C    \    X    X
dnl   profile        C    C    X    \    C
dnl   instrument     C    C    X    C    \

case "x$enable_debug.$enable_optimize.$enable_profile.$enable_instrument" in
	# find conflicts
	xyes.yes.*.*)
		AC_MSG_ERROR([combining --enable-optimize and --enable-debug is not possible])
		;;
	x*.yes.yes.*)
		AC_MSG_ERROR([combining --enable-optimize and --enable-profile is not possible])
		;;
	x*.yes.*.yes)
		AC_MSG_ERROR([combining --enable-optimize and --enable-instrument is not possible])
		;;
	# handle defaults after user requests
	xyes.*.*.*)
		enable_debug=yes
		if test x$enable_optimize != xno ; then
			disable_optimize="(as debug is enabled)"
		fi
		enable_optimize=no
		enable_profile="`echo $enable_profile | sed 's:^def_::'`"
		enable_instrument="`echo $enable_instrument | sed 's:^def_::'`"
		;;
	x*.*.yes.*)
		enable_debug="`echo $enable_debug | sed 's:^def_::'`"
		if test x$enable_optimize != xno ; then
			disable_optimize="(as profile is enabled)"
		fi
		enable_optimize=no
		enable_profile=yes
		enable_instrument="`echo $enable_instrument | sed 's:^def_::'`"
		;;
	x*.*.*.yes)
		enable_debug="`echo $enable_debug | sed 's:^def_::'`"
		if test x$enable_optimize != xno ; then
			disable_optimize="(as instrument is enabled)"
		fi
		enable_optimize=no
		enable_profile="`echo $enable_profile | sed 's:^def_::'`"
		enable_instrument=yes
		;;
	x*.*no.*.*)
		enable_debug="`echo $enable_debug | sed 's:^def_::'`"
		enable_optimize=no
		enable_profile="`echo $enable_profile | sed 's:^def_::'`"
		enable_instrument="`echo $enable_instrument | sed 's:^def_::'`"
		;;
	x*.*yes.*.*) # enable-optimize overrules other defaults
		enable_optimize=yes
		if test x$enable_debug != xno ; then
			disable_debug="(as optimize is enabled)"
		fi
		enable_debug=no
		if test x$enable_profile != xno ; then
			disable_profile="(as optimize is enabled)"
		fi
		enable_profile=no
		if test x$enable_instrument != xno ; then
			disable_instrument="(as optimize is enabled)"
		fi
		enable_instrument=no
		;;
	x*)
		AC_MSG_WARN([unhandled configuration $enable_debug.$enable_optimize.$enable_profile.$enable_instrument, please file a bug on bugs.monetdb.org])
		;;
esac
# make defaults real for flags which don't conflict with anything
enable_assert="`echo $enable_assert | sed 's:^def_::'`"

AC_MSG_CHECKING([for --enable-debug])
if test "x$enable_debug" = xyes; then
	origCFLAGS=$CFLAGS
	dnl  remove "-Ox" as some compilers don't like "-g -Ox" combinations
	CFLAGS=" $CFLAGS "
	CFLAGS="`echo "$CFLAGS" | sed -e 's| -O[[0-9]] | |g' -e 's| -g | |g' -e 's|^ ||' -e 's| $||'`"
	JAVACFLAGS=" $JAVACFLAGS "
	JAVACFLAGS="`echo "$JAVACFLAGS" | sed -e 's| -O | |g' -e 's| -g | |g' -e 's| -g:[[a-z]]* | |g' -e 's|^ ||' -e 's| $||'`"
	dnl  add "-g"
	CFLAGS="$CFLAGS -g"
	JAVACFLAGS="$JAVACFLAGS -g"
	case "$GCC-$host_os" in
	  yes-aix*)
		CFLAGS="$CFLAGS -gxcoff"
		;;
	esac

	changedCFLAGS=
	for flag in $origCFLAGS ; do
		case " $CFLAGS " in
			*" $flag "*) ;;
			*) changedCFLAGS="$changedCFLAGS, removed $flag";;
		esac
	done
	for flag in $CFLAGS ; do
		case " $origCFLAGS " in
			*" $flag "*) ;;
			*) changedCFLAGS="$changedCFLAGS, added $flag";;
		esac
	done
	changedCFLAGS="`echo $changedCFLAGS | sed -e 's|^, ||'`"
	AC_MSG_RESULT([$enable_debug: $changedCFLAGS])
else
	AC_MSG_RESULT([no])
fi

AC_MSG_CHECKING([for --enable-assert])
if test "x$enable_assert" = xno; then
	AC_DEFINE(NDEBUG, 1, [Define if you do not want assertions])
	AC_MSG_RESULT([no])
else
	AC_MSG_RESULT([yes])
fi


AC_MSG_CHECKING([for --enable-optimize])
if test "x$enable_optimize" = xyes; then
	origCFLAGS="$CFLAGS"
	dnl  remove "-g" as some compilers don't like "-g -Ox" combinations
	dnl  remove "-O2" as we add "-Ox" and some compilers don't like "-Oy -Ox" combinations
	CFLAGS=" $CFLAGS "
	CFLAGS="`echo "$CFLAGS" | sed -e 's| -g | |g' -e 's| -O2 | |g' -e 's|^ ||' -e 's| $||'`"
	JAVACFLAGS=" $JAVACFLAGS "
	JAVACFLAGS="`echo "$JAVACFLAGS" | sed -e 's| -g | |g' -e 's| -g:[[a-z]]* | |g' -e 's|^ ||' -e 's| $||'`"
	dnl  Optimization flags
	JAVACFLAGS="$JAVACFLAGS -g:none -O"
	case "$GCC-$CC_ver" in
	yes-clang-*)
	  CFLAGS="$CFLAGS -O3 -fomit-frame-pointer -finline-functions"
	  ;;
	yes-*)
	  dnl -fomit-frame-pointer crashes memprof
	  # -O1 on gcc enables all slight optimisations:
	  #   -fauto-inc-dec -fcprop-registers -fdce -fdefer-pop
	  #   -fdelayed-branch -fdse -fguess-branch-probability
	  #   -fif-conversion2 -fif-conversion -fipa-pure-const
	  #   -fipa-reference -fmerge-constants -fsplit-wide-types
	  #   -ftree-builtin-call-dce -ftree-ccp -ftree-ch
	  #   -ftree-copyrename -ftree-dce -ftree-dominator-opts
	  #   -ftree-dse -ftree-forwprop -ftree-fre -ftree-phiprop
	  #   -ftree-sra -ftree-pta -ftree-ter -funit-at-a-time 
	  # on top of this -fomit-frame-pointer is enabled on machines
	  # where this does not interfere with debugging.
	  # -O2 on gcc enables optimisations which do not involve a
	  # speed-space tradeoff on top of -O1:
	  #   -fthread-jumps -falign-functions  -falign-jumps
	  #   -falign-loops -falign-labels -fcaller-saves -fcrossjumping
	  #   -fcse-follow-jumps  -fcse-skip-blocks
	  #   -fdelete-null-pointer-checks -fexpensive-optimizations
	  #   -fgcse -fgcse-lm -finline-small-functions
	  #   -findirect-inlining -fipa-sra -foptimize-sibling-calls
	  #   -fpeephole2 -fregmove -freorder-blocks -freorder-functions
	  #   -frerun-cse-after-loop -fsched-interblock -fsched-spec
	  #   -fschedule-insns -fschedule-insns2 -fstrict-aliasing
	  #   -fstrict-overflow -ftree-switch-conversion -ftree-pre
	  #   -ftree-vrp
	  # (Gentoo enables -D_FORTIFY_SOURCE=2 starting at -O2)
	  # -O3 on gcc enables some more expensive optimisations on top
	  # of -O2:
	  #  -finline-functions, -funswitch-loops,
	  #  -fpredictive-commoning, -fgcse-after-reload,
	  #  -ftree-vectorize and -fipa-cp-clone 
	  CFLAGS="-O3 -fomit-frame-pointer -pipe ${CFLAGS}"
	  # because we explicitly disable debugging, we can explicitly
	  # enable -fomit-frame-pointer here
	  # notes on -funroll-all-loops:
	  # - does nothing on i?86-linux and x86_64-linux
	  # - speeds up and causes crashes on powerpc-linux
	  # - slows down and makes output incorrect on sparc-solaris
	  # - speeds up and fixes some outputs on sparcv9-solaris
	  # notes on -fast for Darwin:
	  # - ppc: -fast switch causes arithmetic differences, and slower
	  #   running code for SQL, some faster for M5
	  # - x86/x64: -fast switch results in json code producing wrong
	  #   results, or segaults (when used with Mtest)
	  ;;
	*)
	      case "$host-$icc_ver" in
	      dnl handle non-Intel compilers ($icc_ver=""), first
	      *solaris*-)      CFLAGS="$CFLAGS -xO5"
			       ;;
	      *-*-*-)          CFLAGS="$CFLAGS -O2"
			       ;;

	      dnl  With icc-8.*, Interprocedural (IP) Optimization does not seem to work with MonetDB:
	      dnl  With "-ipo -ipo_obj", pass-through linker options ("-Wl,...") are not handled correctly,
	      dnl  and with "-ip -ipo_obj", the resulting Mserver segfaults immediately.
	      dnl  Hence, we skip Interprocedural (IP) Optimization with icc-8.*.
	      x86_64-*-*-8.*)  CFLAGS="$CFLAGS -mp1 -O3 -restrict -unroll               -tpp7 -axWP   ";;
	      x86_64-*-*-9.*)  CFLAGS="$CFLAGS -mp1 -O3 -restrict -unroll               -tpp7 -axWP   ";;

	#     x86_64-*-*-10.*) CFLAGS="$CFLAGS -mp1 -O1 -restrict -unroll                     -axWPT  ";; # K.O.!
	#     x86_64-*-*-10.*) CFLAGS="$CFLAGS                                                        ";; # OK.
	#     x86_64-*-*-10.*) CFLAGS="$CFLAGS -mp1                                                   ";; # OK.
	#     x86_64-*-*-10.*) CFLAGS="$CFLAGS      -O1                                               ";; # K.O.!
	#     x86_64-*-*-10.*) CFLAGS="$CFLAGS      -O2                                               ";; # OK.
	      x86_64-*-*-10.*) CFLAGS="$CFLAGS      -O3                                               ";; # OK.
	#     x86_64-*-*-10.*) CFLAGS="$CFLAGS          -restrict                                     ";;
	#     x86_64-*-*-10.*) CFLAGS="$CFLAGS                    -unroll                             ";;
	#     x86_64-*-*-10.*) CFLAGS="$CFLAGS                                                -axWPT  ";;

	      dnl  We need to use -mp instead of -mp1 as otherwise nextafter() & nextafterf() do not work correctly for 0
	      x86_64-*-*-11.*) CFLAGS="$CFLAGS -mp  -O3 -restrict -unroll                     -axSSE4.2	";; 

	      i*86-*-*-8.*)    CFLAGS="$CFLAGS -mp1 -O3 -restrict -unroll               -tpp6 -axKWNPB";;
	      i*86-*-*-9.*)    CFLAGS="$CFLAGS -mp1 -O3 -restrict -unroll               -tpp6 -axKWNPB";;

	#     i*86-*-*-10.*)   CFLAGS="$CFLAGS -mp1 -O1 -restrict -unroll                     -axWPT  ";; # K.O.!
	#     i*86-*-*-10.*)   CFLAGS="$CFLAGS                                                        ";; # OK.
	#     i*86-*-*-10.*)   CFLAGS="$CFLAGS -mp1                                                   ";; # OK.
	#     i*86-*-*-10.*)   CFLAGS="$CFLAGS      -O1                                               ";; # K.O.!
	#     i*86-*-*-10.*)   CFLAGS="$CFLAGS      -O2                                               ";; # OK.
	      i*86-*-*-10.*)   CFLAGS="$CFLAGS      -O3                                               ";; # OK.
	#     i*86-*-*-10.*)   CFLAGS="$CFLAGS          -restrict                                     ";;
	#     i*86-*-*-10.*)   CFLAGS="$CFLAGS                    -unroll                             ";;
	#     i*86-*-*-10.*)   CFLAGS="$CFLAGS                                                -axWPT  ";;

	      ia64-*-*-8.*)    CFLAGS="$CFLAGS -mp1 -O2 -restrict -unroll               -tpp2 -mcpu=itanium2";;
	      ia64-*-*-9.*)    CFLAGS="$CFLAGS -mp1 -O2 -restrict -unroll               -tpp2 -mcpu=itanium2";;

	#     ia64-*-*-10.*)   CFLAGS="$CFLAGS -mp1 -O2 -restrict -unroll                     -mcpu=itanium2" # OK.
	      ia64-*-*-10.*)   CFLAGS="$CFLAGS -mp1 -O3 -restrict -unroll                     -mcpu=itanium2"
	#     ia64-*-*-10.*)   CFLAGS="$CFLAGS                                                              "
	#     ia64-*-*-10.*)   CFLAGS="$CFLAGS -mp1                                                         "
	#     ia64-*-*-10.*)   CFLAGS="$CFLAGS      -O1                                                     "
	#     ia64-*-*-10.*)   CFLAGS="$CFLAGS      -O2                                                     "
	#     ia64-*-*-10.*)   CFLAGS="$CFLAGS      -O3                                                     "
	#     ia64-*-*-10.*)   CFLAGS="$CFLAGS          -restrict                                           "
	#     ia64-*-*-10.*)   CFLAGS="$CFLAGS                    -unroll                                   "
	#     ia64-*-*-10.*)   CFLAGS="$CFLAGS                                                -mcpu=itanium2"
			       ;;

	      i*86-*-*)        CFLAGS="$CFLAGS -mp1 -O3 -restrict -unroll -ipo -ipo_obj -tpp6 -axiMKW";;
	      ia64-*-*)        CFLAGS="$CFLAGS -mp1 -O2 -restrict -unroll -ipo -ipo_obj -tpp2 -mcpu=itanium2"
			       dnl  With "-O3", ecc does not seem to produce stable/correct? binaries under Linux64
			       dnl  (Mserver produces some incorrect BATpropcheck warnings);
			       dnl  hence, we use only "-O2", here.
			       ;;
	      esac   
	  ;;
	esac
	# for stack-traces with assert, we DO want a frame-pointer
	if test "x$enable_assert" = xyes ; then
		CFLAGS="`echo $CFLAGS | sed 's:-fomit-frame-pointer::'`"
	fi
	changedCFLAGS=
	for flag in $origCFLAGS ; do
		case " $CFLAGS " in
			*" $flag "*) ;;
			*) changedCFLAGS="$changedCFLAGS, removed $flag";;
		esac
	done
	for flag in $CFLAGS ; do
		case " $origCFLAGS " in
			*" $flag "*) ;;
			*) changedCFLAGS="$changedCFLAGS, added $flag";;
		esac
	done
	changedCFLAGS="`echo $changedCFLAGS | sed -e 's|^, ||'`"
	AC_MSG_RESULT([yes: $changedCFLAGS])

	# The default configure invocation when doing an rpmbuild also uses this.
	# In fact, rpmbuild uses -Wp,-D_FORTIFY_SOURCE=2 (cf. /usr/lib/rpm/redhat/macros),
	# but clang 3.3 complains about "argument unused during compilation";
	# hence, we resort to plain "-D_FORTIFY_SOURCE=2", which appears to work fine
	# also with `make rpm`. Well, worst case is that we miss a check that during
	# "normal" build, that is then caught by '-Wp,-D_FORTIFY_SOURCE=2' during `make rpm`.
	MCHECK_ADD_FLAG([-D_FORTIFY_SOURCE=2])
else
	AC_MSG_RESULT([no])
fi

AC_MSG_CHECKING([for --enable-profile])
if test "x$enable_profile" = xyes; then
	AC_DEFINE(PROFILE, 1, [Compiler flag])
	need_profile=yes
	if test "x$GCC" = xyes; then
		CFLAGS="$CFLAGS -pg"
		AC_MSG_RESULT([yes: -pg])
	else
		AC_MSG_RESULT([no])
	fi
else
	AC_MSG_RESULT([no])
fi
AM_CONDITIONAL(PROFILING,test "x$need_profile" = xyes)

AC_MSG_CHECKING([for --enable-instrument])
if test "x$enable_instrument" = xyes; then
	AC_DEFINE(PROFILE, 1, [Compiler flag])
	need_instrument=yes
	if test "x$GCC" = xyes; then
		CFLAGS="$CFLAGS -finstrument-functions -g"
		AC_MSG_RESULT([yes: -finstrument-functions -g])
	else
		AC_MSG_RESULT([no])
	fi
else
	AC_MSG_RESULT([no])
fi

AC_PATH_PROG(BASH,bash, /usr/bin/bash, $PATH)
AC_CHECK_PROG(RM,rm,rm -f)
AC_CHECK_PROG(MV,mv,mv -f)
AC_PROG_LN_S
AC_CHECK_PROGS(DIFF,gdiff diff)
AC_DEFINE_UNQUOTED([DIFF], "$DIFF", [Program to perform diffs])

AC_CHECK_PROGS(RPMBUILD,rpmbuild rpm)

org_have_perl=auto
have_perl=$org_have_perl
PERL=perl
AC_ARG_WITH(perl,
	AS_HELP_STRING([--with-perl=FILE], [perl is installed as FILE]),
	have_perl="$withval")

case "$have_perl" in
	yes|no|auto) ;;
	*)
		PERL="$have_perl"
		have_perl=yes
		;;
esac

if test "x$have_perl" != xno; then
	if test x$cross_compiling != xyes; then
		AC_PATH_PROG(PERL,$PERL,no,$PATH)
		if test "x$PERL" = xno; then
			if test "x$have_perl" != xauto; then
				AC_MSG_ERROR([No Perl executable found])
			fi
			have_perl=no
			why_have_perl="(no Perl executable found)"
		fi
	fi
fi

if test "x$have_perl" != xno; then
	have_perl_libdir=auto
	AC_ARG_WITH(perl-libdir,
		AS_HELP_STRING([--with-perl-libdir=DIR],
			[relative path for Perl library directory (where Perl modules should be installed)]),
		have_perl_libdir="$withval")

	case "$have_perl_libdir" in
		yes|auto)
			if test x$cross_compiling = xyes; then
				AC_MSG_ERROR([Must specify --with-perl-libdir when cross compiling])
			fi
			PERL_LIBDIR=`"$PERL" -MConfig -e '$x=$Config{installvendorarch}; $x =~ s|$Config{vendorprefix}/||; print $x;' 2>/dev/null`
			;;
		no)	;;
		*)
			PERL_LIBDIR="$have_perl_libdir"
			have_perl_libdir=yes
			;;
	esac
else
	# no Perl implies no interpreter
	PERL=false
fi

AC_SUBST(PERL)
AM_CONDITIONAL(HAVE_PERL, test x"$have_perl" != xno)
AC_SUBST(PERL_LIBDIR)

# check major version of python
# check if python2 and python3 exist
# if python2 or python3 doesn't exist, use python if major matches

org_have_python2=auto
have_python2=$org_have_python2
PYTHON2=python2
org_have_python3=auto
have_python3=$org_have_python3
PYTHON3=python3

AC_ARG_WITH(python2,
	AS_HELP_STRING([--with-python2=FILE], [python2 is installed as FILE]),
	have_python2="$withval")

case "$have_python2" in
	yes|no|auto) ;;
	*)
		PYTHON2="$have_python2"
		;;
esac

AC_ARG_WITH(python3,
	AS_HELP_STRING([--with-python3=FILE], [python3 is installed as FILE]),
	have_python3="$withval")

case "$have_python3" in
	yes|no|auto) ;;
	*)
		PYTHON3="$have_python3"
		;;
esac

dnl Figure out a default for PYTHON2 or PYTHON3
AC_PATH_PROG(PYTHON,python,no,$PATH)
PYTHON_MAJ=unknown
if test "x$PYTHON" != xno; then
	AC_MSG_CHECKING([major version of $PYTHON])
	case "`"$PYTHON" -V 2>&1`" in
		"Python 2."[[67]]*)
			PYTHON_MAJ=2
			;;
		"Python 3."*)
			PYTHON_MAJ=3
			;;
	esac
	AC_MSG_RESULT($PYTHON_MAJ)
fi

if test "x$have_python2" != xno; then
	if test x$cross_compiling != xyes; then
		AC_PATH_PROG(PYTHON2,$PYTHON2,no,$PATH)
		if test "x$PYTHON2" = xno; then
			if ( test "x$have_python2" = xyes || test "x$have_python2" = xauto ) && test "x$PYTHON_MAJ" = x2; then
				PYTHON2="$PYTHON"
				have_python2=yes
			elif test "x$have_python2" != xauto; then
				AC_MSG_ERROR([Python 2 executable not found])
			else
				have_python2=no
				why_have_python2="(Python 2 executable not found)"
			fi
		else
			case "`"$PYTHON2" -V 2>&1`" in
			"Python 2."[[67]]*)
				;;
			*)
				if test "x$have_python2" = xauto; then
					have_python2=no
					why_have_python2="(Python 2 executable too old)"
				else
					AC_MSG_ERROR([Python 2 executable too old])
				fi
				;;
			esac
		fi
	fi
fi

if test "x$have_python2" != xno; then
	have_python2_libdir=auto

	AC_ARG_WITH(python2-libdir,
		AS_HELP_STRING([--with-python2-libdir=DIR],
			[relative path for Python 2 library directory (where Python 2 modules should be installed)]),
		have_python2_libdir="$withval")

	case "$have_python2_libdir" in
		yes|auto)
			if test x$cross_compiling = xyes; then
				AC_MSG_ERROR([Must specify --with-python2-libdir when cross compiling])
			fi
			case "$host_os-`"$PYTHON2" -V 2>&1`" in
				darwin9*-*2.5.1)
					# This is the Python installed on OSX Leopard, in
					# later versions of OSX, Python is fixed to return
					# standard output
					PYTHON2_LIBDIR="`"$PYTHON2" -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib(0,1,"'"$Qprefix"'")' 2>/dev/null`/site-packages";;
				*)
					# Use prefix field for Ubuntu Python, bug #3207
					PYTHON2_LIBDIR="`"$PYTHON2" -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib(0,0,"'"$Qprefix"'")' 2>/dev/null`";;
			esac
			PYTHON2_LIBDIR=`echo "$PYTHON2_LIBDIR" | sed "s|^$Qprefix/||"`
			;;
		no)	;;
		$Qprefix/*) dnl dubious
			PYTHON2_LIBDIR=`echo "$have_python2_libdir" | sed "s|^$Qprefix/||"`
			have_python2_libdir=yes
			;;
		*)	PYTHON2_LIBDIR="$have_python2_libdir"
			have_python2_libdir=yes
			;;
	esac
else
	# no Python 2 implies no Python 2 libraries
	have_python2_libdir=no
	PYTHON2_LIBDIR=""
	# and no interpreter
	PYTHON2=false
fi

AC_SUBST(PYTHON2)
AM_CONDITIONAL(HAVE_PYTHON2, test x"$have_python2" != xno)
AC_SUBST(PYTHON2_LIBDIR)

if test "x$have_python3" != xno; then
	if test x$cross_compiling != xyes; then
		AC_PATH_PROG(PYTHON3,$PYTHON3,no,$PATH)
		if test "x$PYTHON3" = xno; then
			if ( test "x$have_python3" = xyes || test "x$have_python3" = xauto ) && test "x$PYTHON_MAJ" = x3; then
				PYTHON3="$PYTHON"
				have_python3=yes
			elif test "x$have_python3" != xauto; then
				AC_MSG_ERROR([Python3 executable not found])
			else
				have_python3=no
				why_have_python3="(Python 3 executable not found)"
			fi
		fi
	fi
fi

if test "x$have_python3" != xno; then
	have_python3_libdir=auto

	AC_ARG_WITH(python3-libdir,
		AS_HELP_STRING([--with-python3-libdir=DIR],
			[relative path for Python 3 library directory (where Python 3 modules should be installed)]),
		have_python3_libdir="$withval")

	case "$have_python3_libdir" in
		yes|auto)
			if test x$cross_compiling = xyes; then
				AC_MSG_ERROR([Must specify --with-python3-libdir when cross compiling])
			fi
			# Use prefix field for Ubuntu Python, bug #3207
			PYTHON3_LIBDIR="`"$PYTHON3" -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(0,0,"'"$Qprefix"'"))' 2>/dev/null`"
			PYTHON3_LIBDIR=`echo "$PYTHON3_LIBDIR" | sed "s|^$Qprefix/||"`
			;;
		no)	;;
		$Qprefix/*) dnl dubious
			PYTHON3_LIBDIR=`echo "$have_python3_libdir" | sed "s|^$Qprefix/||"`
			have_python3_libdir=yes
			;;
		*)	PYTHON3_LIBDIR="$have_python3_libdir"
			have_python3_libdir=yes
			;;
	esac
else
	# no Python 3 implies no Python 3 libraries
	have_python3_libdir=no
	PYTHON3_LIBDIR=""
	# and no interpreter
	PYTHON3=false
fi

AC_SUBST(PYTHON3)
AM_CONDITIONAL(HAVE_PYTHON3, test x"$have_python3" != xno)
AC_SUBST(PYTHON3_LIBDIR)

AM_CONDITIONAL(HAVE_PYTHON, test x"$have_python2" != xno -o x"$have_python3" != xno)

if test "x$PYTHON" = xno; then
	if test "x$PYTHON2" != xno; then
		PYTHON="$PYTHON2"
	elif test "x$PYTHON3" != xno; then
		PYTHON="$PYTHON3"
	fi
fi
AC_SUBST(PYTHON)

# Mtest/Mfilter currently require Python 2
if test "x$enable_testing" != xno ; then
	if test "x$PYTHON2" = xfalse ; then
		enable_testing=no
	fi
fi

RUBY=ruby
AC_PATH_PROG(RUBY,$RUBY,no,$PATH)
have_rubygem_dir=auto
AC_ARG_WITH(rubygem-dir,
	AS_HELP_STRING([--with-rubygem-dir=DIR], [Ruby gems are installed in DIR]),
	have_rubygem_dir="$withval")

case "$have_rubygem_dir" in
	no) ;;
	*)
		if test "x$RUBY" = xno; then
			if test "x$have_rubygem_dir" != xauto; then
				AC_MSG_ERROR([No Ruby executable found])
			fi
			have_rubygem_dir=no
		else
			case "$have_rubygem_dir" in
				yes|auto)
					AC_MSG_CHECKING([where rubygems are stored])
					RUBY_DIR=
					d=`$RUBY -rrbconfig -e "puts Config::CONFIG[['prefix']]" 2>/dev/null`
					RUBY_DIR=`$RUBY -rrbconfig -e "puts Config::CONFIG[['sitelibdir']]" 2>/dev/null | sed -e "s|^$d/||" -e 's/site_ruby/gems/'`
					if test x"$RUBY_DIR" = x ; then
						if test x"$have_rubygem_dir" != xauto; then
							AC_MSG_ERROR([unable to determine rubygems location])
						else
							AC_MSG_RESULT([unable to determine rubygems location])
							RUBY=no
							have_rubygem_dir=no
						fi
					else
						AC_MSG_RESULT([$RUBY_DIR])
					fi
					;;
				*)
					RUBY_DIR="$have_rubygem_dir"
					;;
			esac
		fi
		;;
	*)
		;;
esac
case "$RUBY_DIR" in
${prefix}/*)
	RUBY_DIR="\${prefix}`echo "$RUBY_DIR" | sed "s|^$prefix||"`";;
/*)	;;
*)
	RUBY_DIR="\${prefix}/$RUBY_DIR";;
esac
AC_SUBST(RUBY_DIR)

RUBYGEM=gem
org_have_rubygem=auto
have_rubygem=$org_have_rubygem
AC_ARG_WITH(rubygem,
	AS_HELP_STRING([--with-rubygem=FILE], [ruby gem is installed as FILE]),
	have_rubygem="$withval")

case "$have_rubygem" in
	yes|no|auto)
		;;
	*)
		RUBYGEM="$have_rubygem"
		have_rubygem=yes
		;;
esac

if test "x$have_rubygem" != xno; then
	AC_PATH_PROG(RUBYGEM,$RUBYGEM,no,$PATH)
	if test "x$RUBYGEM" = xno; then
		if test "x$have_rubygem" != xauto; then
			AC_MSG_ERROR([No rubygem executable found])
		fi
		have_rubygem=no
		why_have_rubygem="(no rubygem executable found)"
	fi
fi
AC_SUBST(RUBYGEM)
AM_CONDITIONAL(HAVE_RUBYGEM, test x"$have_rubygem" != xno -a x"$have_rubygem_dir" != xno)

AC_PROG_YACC
case "$YACC" in
	bison*)
		# Ubuntu still comes with an ancient bison that uses defines
		# without checking if they are defined.  This triggers a warning
		# from gcc with -Wundef.  If we have a bison < 2.4.3, then
		# disable the warning.
		BISON_VER=`$YACC --version | head -n1 | sed -e 's/^.* //'`
		if test MONETDB_VERSION_TO_NUMBER(echo $BISON_VER) -lt MONETDB_VERSION_TO_NUMBER(echo 2.4.3); then
			X_CFLAGS="`echo ${X_CFLAGS} | sed -e 's/-Wundef//g'`"
		fi
	;;
	*)
		if test "x$enable_sql" = xyes; then
			AC_MSG_ERROR([MonetDB/SQL requires bison])
		fi
		enable_sql=no
		if test "x$disable_sql" = x; then
			disable_sql="(MonetDB/SQL requires bison)"
		fi
	;;
esac

INSTALL_BACKUP=""
AC_MSG_CHECKING([$INSTALL --backup option])
[ if test "$INSTALL"; then
	inst=`echo $INSTALL | sed 's/ .*//'`
	if test ! "`file $inst | grep 'shell script' 2>/dev/null`" ; then
	    echo "" > c 2>/dev/null
	    $INSTALL --backup=nil c d 1>/dev/null 2>/dev/null
	    if test $? -eq 0; then
	        INSTALL_BACKUP="--backup=nil"
	    fi
	    $INSTALL -C --backup=nil c e 1>/dev/null 2>/dev/null
	    if test $? -eq 0; then
	        INSTALL_BACKUP="-C --backup=nil"
	    fi
	fi
	rm -f c d e 2>/dev/null
fi ]
AC_MSG_RESULT($INSTALL_BACKUP)
AC_SUBST(INSTALL_BACKUP)

SOPREF=lib
case "$host_os" in
mac*)
	dnl Mac OS 9 stuff
	DIRSEP=':'
	QDIRSEP=':'
	AC_ERROR([mac not supported])
	;;
*mingw*)
	DIRSEP='\'
	QDIRSEP='\\'
	PATHSEP=';'
	SOEXT='-0.dll'
	;;
*cygwin*)
	DIRSEP='/'
	QDIRSEP='/'
	PATHSEP=':'
	SOEXT='-0.dll'
	SOPREF=cyg
	;;
*darwin*)
	DIRSEP='/'
	QDIRSEP='/'
	PATHSEP=':'
	SOEXT='.dylib'
	;;
*)
	DIRSEP='/'
	QDIRSEP='/'
	PATHSEP=':'
	SOEXT='.so'
	;;
esac
AC_SUBST(DIRSEP)
AC_SUBST(QDIRSEP)
AC_SUBST(PATHSEP)
AC_SUBST(SOEXT)
AC_DEFINE_UNQUOTED([DIR_SEP], '$QDIRSEP', [Directory separator])
AC_DEFINE_UNQUOTED([DIR_SEP_STR], "$QDIRSEP", [Directory separator])
AC_DEFINE_UNQUOTED([PATH_SEP], '$PATHSEP', [Path separator])
AC_DEFINE_UNQUOTED([PATH_SEP_STR], "$PATHSEP", [Path separator])
AC_DEFINE_UNQUOTED([SO_PREFIX], "$SOPREF", [Shared Object prefix])
AC_DEFINE_UNQUOTED([SO_EXT], "$SOEXT", [Shared Object extension])

case "$host_os" in
    cygwin*)
	;;
    *)
	CYGPATH_W=echo
	CYGPATH_WP=echo
	AC_SUBST(CYGPATH_W)
	AC_SUBST(CYGPATH_WP)
	;;
esac

AC_ARG_WITH(ant,
	AS_HELP_STRING([--with-ant=FILE], [ant is installed as FILE]),
	ANT="$withval",
	ANT=ant)
case "$ANT" in
yes|auto)
	ANT=ant
	;;
esac
case "$ANT" in
no)	;;
/*)
	AC_MSG_CHECKING(whether $ANT exists and is executable)
	if test -x "$ANT"; then
		AC_MSG_RESULT(yes)
	else
		AC_MSG_RESULT(no)
		ANT=no
	fi
	;;
*)
	AC_PATH_PROG(ANT,$ANT,no,$PATH)
	;;
esac
AC_SUBST(ANT)

dnl  default javac flags
JAVACFLAGS="$JAVACFLAGS -g:none -O"
AC_SUBST(JAVACFLAGS)

JAVA_VERSION=""
JAVA="java"
JAVAC="javac"
JAR="jar"
JAVADOC="javadoc"
org_have_java=auto
AC_ARG_WITH(java,
	AS_HELP_STRING([--with-java=DIR],
		[java, javac, jar and javadoc are installed in DIR/bin]),
	have_java="$withval",
	have_java=$org_have_java)
JPATH=$PATH
case $have_java in
yes|no|auto)
	;;
*)
	JPATH="$withval/bin:$JPATH"
	;;
esac
if test "x$have_java" != xno; then
	AC_PATH_PROG(JAVA,java,,$JPATH)
	if test "x$JAVA" != "x"; then
		JAVA_VERSION=[`"$JAVA" -version 2>&1 | grep '[0-9]\.[0-9]' | head -n1 | sed -e 's|^[^0-9]*||' -e 's|[^0-9]*$||'`]
	fi

	AC_PATH_PROG(JAVAC,javac,,$JPATH)
	AC_PATH_PROG(JAR,jar,,$JPATH)
	AC_PATH_PROG(JAVADOC,javadoc,,$JPATH)
	if test "x$have_java" = xyes; then
		JAVA_HOME="`echo $JAVAC | sed 's:/bin/javac$::'`"
	fi
	if test "x$JAVAC" = "x"; then
		if test "x$have_java" = xyes; then
			AC_MSG_ERROR([No javac found])
		fi
		have_java=no
		why_have_java="(no javac found)"
	elif test "x$JAR" = "x"; then
		if test "x$have_java" = xyes; then
			AC_MSG_ERROR([No jar found])
		fi
		have_java=no
		why_have_java="(no jar found)"
	else
		 have_java=yes
	fi

	if test "x$have_java" != xyes; then
		JAVA_VERSION=""
		JAVA=""
		JAVAC=""
		JAR=""
		JAVADOC=""
		CLASSPATH=""
		JAVA_HOME=""
	fi
	if test x"$ANT" = xno; then
		have_java="no"
		why_have_java="(no ant found)"
	fi
fi
AC_SUBST(JAVA_VERSION)
AC_SUBST(JAVA)
AC_SUBST(JAVAC)
AC_SUBST(JAR)
AC_SUBST(JAVADOC)
AC_SUBST(CLASSPATH)
AC_SUBST(JAVA_HOME)

org_have_java_jdbc=no
have_java_jdbc=$org_have_java_jdbc
case $have_java-$enable_jdbc in
*-no)
	;;
no-yes)
	AC_MSG_ERROR([MonetDB JDBC requires ant and Java])
	;;
no-*)
	enable_jdbc=no
	if test x$ANT = xno ; then
		disable_jdbc="(ant is required to build MonetDB JDBC)"
	else
		disable_jdbc="(Java is required to build MonetDB JDBC)"
	fi
	;;
*)
	if test MONETDB_VERSION_TO_NUMBER(echo $JAVA_VERSION) -ge MONETDB_VERSION_TO_NUMBER(echo "1.6") ; then
		have_java_jdbc=yes
	else
		if test "x$enable_jdbc" = xyes; then
			AC_MSG_ERROR([MonetDB JDBC requires ant and Java 6 or higher])
		else
			enable_jdbc=no
			disable_jdbc="(MonetDB JDBC currently requires Java 6 or higher to build)"
		fi
	fi
	;;
esac
AM_CONDITIONAL(HAVE_JAVAJDBC,test x$have_java_jdbc != xno)

org_have_java_control=no
have_java_control=$org_have_java_control
case $have_java-$enable_control in
*-no)
	;;
no-yes)
	AC_MSG_ERROR([Merovingian control requires ant and Java])
	;;
no-*)
	enable_control=no
	if test x$ANT = xno ; then
		disable_control="(ant is required to build merovingian Java control library)"
	else
		disable_control="(Java is required to build merovingian Java control library)"
	fi
	;;
*)
	req_java_ver_min=1.6 # >= $req_java_ver_min required
	if test MONETDB_VERSION_TO_NUMBER(echo $JAVA_VERSION) -ge MONETDB_VERSION_TO_NUMBER(echo "$req_java_ver_min"); then
		have_java_control=yes
	else
		if test "x$enable_control" = xyes; then
			AC_MSG_ERROR([Merovingian control requires ant and Java >= $req_java_ver_min.])
		else
			enable_control=no
			disable_control="(merovingian Java control library requires Java >= $req_java_ver_min)"
		fi
	fi
	;;
esac
AM_CONDITIONAL(HAVE_JAVAMEROCONTROL,test x$have_java_control != xno)

if test x$have_java_jdbc = xno -a x$have_java_control = xno; then
	# no point doing anything with Java if all Java packages are disabled
	have_java=no
	if test "x$why_have_java" = x ; then
		why_have_java="(have_java_jdbc = no && have_java_control = no)"
	fi
fi
AM_CONDITIONAL(HAVE_JAVA,test x$have_java != xno)

dnl     checks for libraries
dnl check for bz2 (de)compression library
org_have_bz2=auto
have_bz2=$org_have_bz2
BZ_CFLAGS=""
BZ_LIBS=""
AC_ARG_WITH(bz2,
	AS_HELP_STRING([--with-bz2=DIR],
		[bz2 library is installed in DIR]),
	have_bz2="$withval")

case "$have_bz2" in
	yes|no|auto) ;;
	*)
		BZ_CFLAGS="-I$withval/include"
		BZ_LIBS="-L$withval/lib"
		;;
esac

AC_MSG_CHECKING(for bzip2) 
if test "x$have_bz2" != xno; then
	save_CPPFLAGS="$CPPFLAGS"
	CPPFLAGS="$CPPFLAGS $BZ_CFLAGS"
	save_LIBS="$LIBS"
	LIBS="$LIBS $BZ_LIBS -lbz2"
	AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
#include <bzlib.h>]], [[(void)BZ2_bzopen("","");]])],
		BZ_LIBS="$BZ_LIBS -lbz2",
		[ if test "x$have_bz2" != xauto; then
			AC_MSG_ERROR([bz2 library not found])
		  fi
		  have_bz2=no
		  why_have_bz2="(bz2 library not found)" ])
	LIBS="$save_LIBS"
	CPPFLAGS="$save_CPPFLAGS"
fi

if test "x$have_bz2" != xno; then
	AC_DEFINE(HAVE_LIBBZ2, 1, [Define if you have the bz2 library])
	AC_MSG_RESULT([yes: $BZ_LIBS])
else
	BZ_CFLAGS=""
	BZ_LIBS=""
	AC_MSG_RESULT([no])
fi

AC_SUBST(BZ_CFLAGS)
AC_SUBST(BZ_LIBS)
AM_CONDITIONAL(HAVE_LIBBZ2,test x$have_bz2 != xno)

DL_LIBS=""
AC_CHECK_LIB(dl, dlopen, [ DL_LIBS="-ldl" ] )
AC_SUBST(DL_LIBS)

MATH_LIBS=""
AC_CHECK_LIB(m, sqrt, [ MATH_LIBS="-lm" ] )
AC_SUBST(MATH_LIBS)

MALLOC_LIBS=""
AC_CHECK_LIB(umem, malloc, [ MALLOC_LIBS="-lumem" ],
	AC_CHECK_LIB(mtmalloc, malloc, [ MALLOC_LIBS="-lmtmalloc" ],
		AC_CHECK_LIB(malloc, malloc, [ MALLOC_LIBS="-lmalloc" ] )))
AC_SUBST(MALLOC_LIBS)

KVM_LIBS=""
AC_CHECK_LIB(kvm, kvm_open, [ KVM_LIBS="-lkvm" ] )
AC_SUBST(KVM_LIBS)

save_LIBS="$LIBS"
LIBS="$LIBS $MALLOC_LIBS"
AC_CHECK_FUNCS(mallopt)
AC_CHECK_FUNC(mallinfo, AC_TRY_COMPILE([$ac_includes_default
#include <malloc.h>], [struct mallinfo m;int x[[1+sizeof(m.usmblks)-sizeof(void *)]]], AC_DEFINE(HAVE_USEFUL_MALLINFO, 1, [Define if you have mallinfo])))
LIBS="$save_LIBS"

dnl libpthread
org_have_pthread=auto
have_pthread=$org_have_pthread
PTHREAD_LIBS=""
PTHREAD_INCS=""
PTHREAD_EXTRA=""
AC_ARG_WITH(pthread,
	AS_HELP_STRING([--with-pthread=DIR],
		[pthread library is installed in DIR]), 
	have_pthread="$withval")

case "$have_pthread" in
yes|no|auto)
	;;
*)
	PTHREAD_LIBS="-L$withval/lib"
	PTHREAD_INCS="-I$withval/include"
	;;
esac

if test "x$have_pthread" != xno; then

	save_CPPFLAGS="$CPPFLAGS"
	case $host_os in
		*mingw*)
			PTHREAD_EXTRA="-D_DDL"
			CPPFLAGS="$CPPFLAGS $PTHREAD_INCS/pthread $PTHREAD_EXTRA"
			AC_CHECK_HEADER(pthread.h,[AC_DEFINE(HAVE_PTHREAD_H, 1,
								[Define if you have the pthread.h])
					AC_CHECK_HEADERS(pthread.h semaphore.h sched.h) 
					PTHREAD_INCS="$PTHREAD_INCS/pthread"]) 
			;;
		*)
			CPPFLAGS="$CPPFLAGS $PTHREAD_INCS $PTHREAD_EXTRA"
			AC_CHECK_HEADERS(pthread.h semaphore.h sched.h) 
			;;
	esac
	CPPFLAGS="$save_CPPFLAGS"

	save_LIBS="$LIBS"
	save_CPPFLAGS="$CPPFLAGS"
	case $GCC-$have_pthread-$CC_ver in
		yes-auto-clang-5.*|yes-yes-clang-5.*|yes-auto-clang-6.*|yes-yes-clang-6.*)
			# clang 5.*/6.* (Xcode 6.0) does not
			# seem to have / require -pthread as compiler
			# option; on Mac OS X Yosamite, "Apple LLVM 
			# version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)"
			# complains about "error: argument unused during
			# compilation: '-pthread'".
			# However, disabling -pthread completely might be
			# too redical/harsh; see also
			# https://www.monetdb.org/pipermail/developers-list/2014-March/004264.html
			# a better alternative might be required but is
			# still pending ...
		;;
		yes-auto-*|yes-yes-*)
			# use GCC's knowledge about the target platform, sets flags
			# for both the preprocessor as well as the linker
			PTHREAD_INCS="-pthread"
			PTHREAD_LIBS="-pthread"
			CPPFLAGS="$CPPFLAGS $PTHREAD_INCS"
			LIBS="$LIBS $PTHREAD_LIBS"
		;;
		*)
			# ok, do old-fashioned stuff
			CPPFLAGS="$CPPFLAGS $PTHREAD_INCS" # in case user did --with-pthreads
			LIBS="$LIBS $PTHREAD_LIBS"
			pthread_found=yes
			AC_SEARCH_LIBS([sem_init], [pthreadGC2 pthreadGC1 pthreadGC pthread],
				[test "$ac_cv_search_sem_init" = "none required" || LIBS="$LIBS $ac_cv_search_sem_init"],
				[pthread_found=no])
			if test x"$pthread_found" = xno ; then
				pthread_found=yes
				dnl sun
				AC_SEARCH_LIBS([sem_post], [pthread],
					[LIBS="$LIBS -lpthread -lposix4"],
					[pthread_found=no],
					"-lposix4")
			fi
			if test x"$pthread_found" = xno ; then
				pthread_found=yes
				dnl hp-ux
				AC_SEARCH_LIBS([sem_post], [pthread],
					[LIBS="$LIBS -lpthread -lrt"],
					[pthread_found=no],
					"-lrt")
			fi
			if test x"$pthread_found" = xno ; then
				if test "x$have_pthread" != xauto ; then
					AC_MSG_ERROR([pthread library not found])
				fi
				have_pthread=no
				why_have_pthread="(pthread library not found)"
			fi
			PTHREAD_LIBS="$LIBS"
		;;
	esac

	AC_SEARCH_LIBS(pthread_kill, , 
		AC_DEFINE(HAVE_PTHREAD_KILL, 1,
			[Define if you have the pthread_kill function]))
	AC_SEARCH_LIBS(pthread_sigmask, , 
		AC_DEFINE(HAVE_PTHREAD_SIGMASK, 1,
			[Define if you have the pthread_sigmask function]))
	AC_SEARCH_LIBS(pthread_kill_other_threads_np, , 
		AC_DEFINE(HAVE_PTHREAD_KILL_OTHER_THREADS_NP, 1,
			[Define if you have the pthread_kill_other_threads_np function]))
	AC_SEARCH_LIBS(pthread_setschedprio, , 
		AC_DEFINE(HAVE_PTHREAD_SETSCHEDPRIO, 1,
			[Define if you have the pthread_setschedprio function]))
	dnl this function very ugly is overloaded with semaphore stuff
	dnl so we DO need to check for it, for platforms which have it
	dnl in a separate lib, like Solaris
	AC_SEARCH_LIBS(sem_wait, rt)

	LIBS="$save_LIBS"
	CPPFLAGS="$save_CPPFLAGS"

fi
AC_MSG_CHECKING([whether we have pthread support])
if test "x$have_pthread" != xno; then
	AC_DEFINE(HAVE_LIBPTHREAD, 1, [Define if you have the pthread library])
	PTHREAD_INCS="$PTHREAD_INCS $PTHREAD_EXTRA"
	dnl CPPFLAGS="$CPPFLAGS $PTHREAD_INCS"
	AC_MSG_RESULT([yes: $PTHREAD_INCS $PTHREAD_LIBS])
else
	PTHREAD_LIBS=""
	PTHREAD_INCS=""
	AC_MSG_RESULT([no])
	AC_MSG_ERROR("MonetDB requires libpthread (try --with-pthread)")
fi
AC_SUBST(PTHREAD_LIBS)
AC_SUBST(PTHREAD_INCS)

dnl libreadline
org_have_readline=auto
have_readline=$org_have_readline
READLINE_LIBS=""
READLINE_INCS=""
AC_ARG_WITH(readline,
	AS_HELP_STRING([--with-readline=DIR],
		[readline library is installed in DIR]), 
	have_readline="$withval")

case "$have_readline" in
	yes|no|auto) ;;
	*)
		READLINE_LIBS="-L$have_readline/lib"
		READLINE_INCS="-I$have_readline/include"
		;;
esac

save_LIBS="$LIBS"
LIBS="$LIBS $READLINE_LIBS"
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $READLINE_INCS"
if test "x$have_readline" != xno; then
	dnl use different functions in the cascade of AC_CHECK_LIB
	dnl calls since configure may cache the results
	AC_CHECK_HEADER(readline/readline.h,
		AC_CHECK_LIB(readline, readline,
			READLINE_LIBS="$READLINE_LIBS -lreadline",
			[ AC_CHECK_LIB(readline, rl_history_search_forward,
				READLINE_LIBS="$READLINE_LIBS -lreadline -ltermcap",
				[ AC_CHECK_LIB(readline, rl_reverse_search_history,
					READLINE_LIBS="$READLINE_LIBS -lreadline -lncurses",
					[ if test "x$have_readline" = xyes; then
						AC_MSG_ERROR([readline library not found])
					  fi
					  have_readline=no
					  why_have_readline="(readline library not found)" ],
					-lncurses)],
				-ltermcap)],
			),
		[ if test "x$have_readline" = xyes; then
			AC_MSG_ERROR([readline header file not found])
		  fi
		  have_readline=no
		  why_have_readline="(readline header file not found)" ])
fi

if test "x$have_readline" != xno; then
	dnl provide an ACTION-IF-FOUND, or else all subsequent checks
	dnl that involve linking will fail!
	AC_CHECK_LIB(readline, rl_completion_matches,
		[AC_MSG_CHECKING([whether rl_completion_func_t exists])
		 AC_TRY_COMPILE([$ac_includes_default
#include <readline/readline.h>],[
	rl_completion_func_t *func = NULL;],
			[AC_MSG_RESULT([yes])],
			[ if test "x$have_readline" != xauto; then
				AC_MSG_ERROR([readline/readline.h does not contain rl_completion_func_t, is it GNU readline?])
			  else
				AC_MSG_RESULT([no])
			  fi
			  have_readline=no
			  why_have_readline="(readline/readline.h does not contain rl_completion_func_t, is it GNU readline?)" ])],
		[ if test "x$have_readline" != xauto; then
			AC_MSG_ERROR([readline library does not contain rl_completion_matches])
		  fi
		  have_readline=no
		  why_have_readline="(readline library does not contain rl_completion_matches)" ],
		  $READLINE_LIBS)
fi
CPPFLAGS="$save_CPPFLAGS"
LIBS="$save_LIBS"

if test "x$have_readline" != xno; then
	AC_DEFINE(HAVE_LIBREADLINE, 1,
		[Define if you have the readline library])
else
	READLINE_LIBS=""
	READLINE_INCS=""
fi
AC_SUBST(READLINE_LIBS)
AC_SUBST(READLINE_INCS)

m4_ifndef([AM_ICONV],
  [m4_fatal([Could not locate the iconv autoconf
	macros. These are usually located in /usr/share/aclocal/iconv.m4 and
	provided by the gettext package.  If your macros are in a different
	location, try setting the environment variable
	M4DIRS="-I/other/macro/dir" before running ./bootstrap or autoreconf
	again.])])

AM_ICONV

dnl UUID: remember that most UNIX systems have uuid_* functions in their
dnl       libc, not as separate library, such as from util-linux.  We
dnl       can't just use pkg-config check because of that.
save_LIBS="$LIBS"
LIBS=
AC_SEARCH_LIBS([uuid_generate], [uuid], [AC_DEFINE([HAVE_UUID], 1, [uuid])])
UUID_LIBS="$LIBS"
LIBS="$save_LIBS"
AC_SUBST(UUID_LIBS)

dnl OpenSSL library
dnl required for MonetDB5 (and SQL), optional otherwise
PKG_CHECK_MODULES([openssl], [openssl],
	[have_openssl=yes],
	[have_openssl=no; why_have_openssl="(OpenSSL library not found)"])
case "$enable_monetdb5-$have_openssl" in
yes-no)
	AC_MSG_ERROR([OpenSSL library not found but required for MonetDB5])
	;;
auto-no)
	enable_monetdb5=no
	if test "x$disable_monetdb5" = x; then
		disable_monetdb5="(OpenSSL library not found but required for MonetDB5)"
	fi
	;;
*-yes)
	save_LIBS="$LIBS"
	LIBS="$LIBS $openssl_LIBS"
	AC_CHECK_FUNCS([MD5 RIPEMD160 SHA1 SHA224 SHA256 SHA384 SHA512])
	LIBS="$save_LIBS"
	if eval test \"x\$ac_cv_func_$MONETDB5_PASSWDHASH\" != x"yes"; then
		case "$enable_monetdb5" in
		yes)
			AC_MSG_ERROR([OpenSSL library found but checksum algorithm required for MonetDB5 not found])
			;;
		auto)
			enable_monetdb5=no
			if test "x$disable_monetdb5" = x; then
				disable_monetdb5="(OpenSSL library found but checksum algorithm required for MonetDB5 not found)"
			fi
			;;
		*)
			AC_MSG_WARN([OpenSSL library found but required checksum algorithm not found, so disabling])
			;;
		esac
		have_openssl=no
		why_have_openssl="(OpenSSL library found but required checksum algorithm not found)"
	fi
	;;
esac
if test x"$have_openssl" = x"yes"; then
	AC_DEFINE(HAVE_OPENSSL, 1, [Define if you have the OpenSSL library])
fi

dnl PCRE library
dnl required for MonetDB5 (and SQL), optional otherwise
req_pcre_ver='4.5'
PKG_CHECK_MODULES([pcre], [libpcre >= $req_pcre_ver],
	[have_pcre=yes], [have_pcre=no; why_have_pcre="(libpcre >= $req_pcre_ver not found)"])
if test "x$have_pcre" = xyes; then
	AC_MSG_CHECKING(whether pcre comes with UTF-8 support)
	save_LIBS="$LIBS"
	LIBS="$LIBS $pcre_LIBS"
	save_CFLAGS="$CFLAGS"
	CFLAGS="$CFLAGS $pcre_CFLAGS"
	AC_RUN_IFELSE([AC_LANG_PROGRAM(
		[[#include <pcre.h>]],
		[[int rc; pcre_config(PCRE_CONFIG_UTF8, &rc); exit(!rc);]])],
		AC_MSG_RESULT([yes]),
		have_pcre=no; why_have_pcre="(libpcre found but no UTF-8 support)"; AC_MSG_RESULT([no]),
		AC_MSG_RESULT([assuming yes]))
	LIBS="$save_LIBS"
	CFLAGS="$save_CFLAGS"
fi
if test "x$have_pcre" = xyes; then
	AC_DEFINE(HAVE_LIBPCRE, 1, [Define if you have the pcre library])
fi
AM_CONDITIONAL(HAVE_PCRE, test x"$have_pcre" != xno)
case "$enable_monetdb5-$have_pcre" in
yes-no)
	AC_MSG_ERROR([PCRE library not found but required for MonetDB5])
	;;
auto-no)
	enable_monetdb5=no
	if test "x$disable_monetdb5" = x; then
		disable_monetdb5="(PCRE library not found but required for MonetDB5)"
	fi
	;;
esac


PKG_CHECK_MODULES([libxml2], [libxml-2.0], [have_libxml2="yes"], [have_libxml2="no"; why_have_libxml2="(libxml2 not found)"])
case "$enable_monetdb5-$have_libxml2" in
yes-no)
	AC_MSG_ERROR([libxml2 library not found but required for MonetDB5])
	;;
auto-no)
	enable_monetdb5=no
	if test "x$disable_monetdb5" = x; then
		disable_monetdb5="(libxml2 library not found but required for MonetDB5)"
	fi
	;;
esac


org_have_raptor=no
have_raptor=$org_have_raptor
if test "x$enable_rdf" != xno; then
	req_raptor_ver='1.4.16'
	PKG_CHECK_MODULES([raptor], [raptor],
		[AC_DEFINE(HAVE_RAPTOR, 1, [Define if you have raptor installed])
		 have_raptor="yes"],
		[if test "x$enable_rdf" = xyes; then AC_MSG_ERROR([raptor library required for RDF support]); fi
		 have_raptor="no"; why_have_raptor="(raptor library not found)"
		 enable_rdf=no; disable_rdf="(raptor library not found)"])
fi
AM_CONDITIONAL(HAVE_RAPTOR, test x"$have_raptor" != xno)

AM_CONDITIONAL(ENABLE_DATACELL, test x"$enable_datacell" != xno)

PKG_CHECK_MODULES([curl], [libcurl], [have_curl="yes"], [have_curl="no"; why_have_curl="(libcurl not found)"])
if test x"$have_curl" = x"yes" ; then
	AC_DEFINE(HAVE_CURL, 1, [Define if you have the cURL library])
	AC_SUBST(PKG_CURL, libcurl)
fi
AM_CONDITIONAL(HAVE_CURL, test x"$have_curl" != xno)

PKG_CHECK_MODULES([zlib], [zlib], [have_zlib="yes"], [have_zlib="no"; why_have_zlib="(zlib not found)"])
if test x"$have_zlib" = x"yes" ; then
	AC_DEFINE(HAVE_LIBZ, 1, [Define if you have the z library])
	AC_SUBST(PKG_ZLIB, zlib)
fi
AM_CONDITIONAL(HAVE_LIBZ, test x"$have_zlib" != xno)

org_have_valgrind=no
have_valgrind=$org_have_valgrind
AC_ARG_WITH(valgrind,
	AS_HELP_STRING([--with-valgrind],
		[include valgrind support (default=no)]),
	have_valgrind=$withval)
if test "x$have_valgrind" != xno; then
	PKG_CHECK_MODULES([valgrind], [valgrind],
		[AC_DEFINE(HAVE_VALGRIND, 1, [Define if you have valgrind installed and want to use it])],
		[if test "x$have_valgrind" = xyes; then AC_MSG_ERROR([no valgrind support found]); fi])
fi

# check for sphinxclient
org_have_sphinxclient="auto"
have_sphinxclient=$org_have_sphinxclient
AC_ARG_WITH(sphinxclient,
    AS_HELP_STRING([--with-sphinxclient=DIR],[sphinxclient library is installed in DIR]),
    [have_sphinxclient="$withval"])
if test "x$have_sphinxclient" != xno; then
	case "$have_sphinxclient" in
	auto|yes)
	    ;;
	*)
	    SPHINXCLIENT_CFLAGS="-I$have_sphinxclient/include"
	    SPHINXCLIENT_LIBS="-L$have_sphinxclient/lib"
	    ;;
	esac

	save_CPPFLAGS="$CPPFLAGS"
	save_LDFLAGS="$LDFLAGS"
	CPPFLAGS="$CPPFLAGS $SPHINXCLIENT_CFLAGS"
	LDFLAGS="$LDFLAGS $SPHINXCLIENT_LIBS"
	AC_CHECK_HEADER(sphinxclient.h,
		AC_CHECK_LIB(sphinxclient, sphinx_create,
			AC_DEFINE(HAVE_SPHINXCLIENT, 1, [Define if you have the sphinxclient library])
			have_sphinxclient=yes
			SPHINXCLIENT_LIBS="$SPHINXCLIENT_LIBS -lsphinxclient",
			[ if test "x$have_sphinxclient" != xauto; then AC_MSG_ERROR([-lsphinxclient library not found]); fi
			  have_sphinxclient=no; why_have_sphinxclient="(sphinxclient library not found)" ]),
		[ if test "x$have_sphinxclient" != xauto; then AC_MSG_ERROR([sphinxclient.h header not found]); fi
		  have_sphinxclient=no; why_have_sphinxclient="(sphinxclient.h header not found)" ])
	LDFLAGS="$save_LDFLAGS"
	CPPFLAGS="$save_CPPFLAGS"
fi
AC_SUBST(SPHINXCLIENT_CFLAGS, $SPHINXCLIENT_CFLAGS)
AC_SUBST(SPHINXCLIENT_LIBS, $SPHINXCLIENT_LIBS)
AM_CONDITIONAL(HAVE_SPHINXCLIENT, test x"$have_sphinxclient" != xno)

have_libr=no
if test "x$enable_rintegration" != xno; then
	case "$enable_rintegration" in
	yes|auto)
		XPATH="$PATH"
		;;
	/*)
		XPATH="$enable_rintegration"
		enable_rintegration=yes
		;;
	*)
		AC_MSG_ERROR([--enable-rintegration value must be yes|no|auto|absolute path of R cmd])
		;;
	esac
   	AC_PATH_PROG(RCMD,R,,$XPATH)
   	if test "x$RCMD" = x; then
      		if test "x$enable_rintegration" = xyes; then
			AC_MSG_ERROR([libR library required for R integration support])
		else
			have_libr="no"
		 	why_have_libr="(libR library not found)"
			enable_rintegration=no
			disable_rintegration="(libR library not found)"
		fi
	elif RHOME=`$RCMD RHOME` && libr_CFLAGS=`$RCMD CMD config --cppflags` && libr_LIBS=`$RCMD CMD config --ldflags`; then
		have_libr=yes
		AC_DEFINE(HAVE_LIBR, 1, [Define if you have libR installed])
		AC_SUBST(libr_CFLAGS, $libr_CFLAGS)
		AC_SUBST(libr_LIBS, $libr_LIBS)
		AC_SUBST(RHOME, $RHOME)
		AC_DEFINE_UNQUOTED(RHOME, "$RHOME", [The home of R])
	fi
fi
AM_CONDITIONAL(HAVE_LIBR, test x"$have_libr" != xno)

# ODBC, only used by ODBC driver
if test "x$enable_odbc" != xno; then
	have_unixodbc=auto
	ODBC_INCS=''
	ODBCINST_LIBS=''
	ODBC_LIBS=''
	AC_ARG_WITH(unixodbc,
		AS_HELP_STRING([--with-unixodbc=DIR],
			[unixODBC library is installed in DIR]),
		have_unixodbc="$withval")
	if test "x$have_unixodbc" != xno; then
		case "$have_unixodbc" in
		yes|auto)
			;;
		*)
			ODBC_INCS="-I$have_unixodbc/include"
			ODBCINST_LIBS="-L$have_unixodbc/lib"
			ODBC_LIBS="-L$have_unixodbc/lib"
			;;
		esac
		save_CPPFLAGS="$CPPFLAGS"
		CPPFLAGS="$CPPFLAGS $ODBC_INCS"
		AC_CHECK_HEADER(odbcinst.h,
			AC_DEFINE(HAVE_ODBCINST_H, 1, [Define to 1 if you have the <odbcinst.h> header file.]),
			[if test "x$have_unixodbc" != xauto; then AC_MSG_ERROR([odbcinst.h not found]); fi
			 have_unixodbc=no; why_have_unixodbc="(odbcinst.h not found)"])
		CPPFLAGS="$save_CPPFLAGS"
	fi
	if test "x$have_unixodbc" != xno; then
		save_LIBS="$LIBS"
		LIBS="$LIBS $ODBCINST_LIBS"
		AC_CHECK_LIB(odbcinst,
			SQLGetPrivateProfileString, :,
			[if test "x$have_unixodbc" != xauto; then AC_MSG_ERROR([-lodbcinst not found]); fi
			 have_unixodbc=no; why_have_unixodbc="(odbcinst library not found)"])
		LIBS="$save_LIBS"
	fi
	if test "x$have_unixodbc" != xno; then
		save_LIBS="$LIBS"
		LIBS="$LIBS $ODBC_LIBS"
		AC_CHECK_LIB(odbc,
			SQLGetDiagRec, :,
			[if test "x$have_unixodbc" != xauto; then AC_MSG_ERROR([-lodbc not found]); fi
			 have_unixodbc=no; why_have_unixodbc="(odbc library not found)"])
		LIBS="$save_LIBS"
	fi
	if test "x$have_unixodbc" != xno; then
		ODBCINST_LIBS="$ODBCINST_LIBS -lodbcinst"
		ODBC_LIBS="$ODBC_LIBS -lodbc"
		AC_DEFINE(HAVE_SQLGETPRIVATEPROFILESTRING, 1,
			[Define if you have the SQLGetPrivateProfileString function])
	fi
	if test "x$have_unixodbc" != xno; then
		AC_MSG_CHECKING([checking whether SQLColAttribute uses SQLLEN * or SQLPOINTER])
		save_CPPFLAGS="$CPPFLAGS"
		CPPFLAGS="$CPPFLAGS $ODBC_INCS"
		AC_COMPILE_IFELSE([
			AC_LANG_PROGRAM([[
				#include <sql.h>
				SQLRETURN SQL_API
				SQLColAttribute(SQLHSTMT hStmt, SQLUSMALLINT nCol, SQLUSMALLINT nFieldIdentifier, SQLPOINTER pszValue, SQLSMALLINT nValueLengthMax, SQLSMALLINT *pnValueLength, SQLLEN *pnValue) {
					(void) hStmt;
					(void) nCol;
					(void) nFieldIdentifier;
					(void) pszValue;
					(void) nValueLengthMax;
					(void) pnValueLength;
					(void) pnValue;
					return SQL_SUCCESS;}]],
				[[SQLColAttribute(0,0,0,0,0,0,0);]])],
			[lenp_or_pointer_t='SQLLEN *'],
			[lenp_or_pointer_t=SQLPOINTER])
		CPPFLAGS="$save_CPPFLAGS"
		AC_MSG_RESULT([using "$lenp_or_pointer_t"])
		AC_DEFINE_UNQUOTED(LENP_OR_POINTER_T, $lenp_or_pointer_t,
			[Define as SQLLEN * or SQLPOINTER depending on the include file])
	fi
	AC_SUBST(ODBC_INCS)
	AC_SUBST(ODBCINST_LIBS)
	AC_SUBST(ODBC_LIBS)
	case "x${enable_odbc}x${have_unixodbc}" in
		xautoxno)
			enable_odbc=no
			disable_odbc="(unixODBC library required for ODBC driver)"
			;;
		xyesxno)
			AC_MSG_ERROR([unixODBC required for building ODBC driver])
			;;
	esac
else
	have_unixodbc=no
	why_have_unixodbc="(ODBC disabled)"
fi
AM_CONDITIONAL(HAVE_ODBC, test x$have_unixodbc != xno)

# mseed, only used by sql
org_have_mseed="auto"
have_mseed=$org_have_mseed
AC_ARG_WITH(mseed,
    AS_HELP_STRING([--with-mseed=DIR],[mseed library is installed in DIR]),
    [have_mseed="$withval"])
if test "x$have_mseed" != xno; then

	case "$have_mseed" in
	auto|yes)
	    ;;
	*)
	    MSEED_CFLAGS="-I$have_mseed/include"
	    MSEED_LIBS="-L$have_mseed/lib -lmseed"
	    ;;
	esac

	save_CPPFLAGS="$CPPFLAGS"
	save_LDFLAGS="$LDFLAGS"
	CPPFLAGS="$CPPFLAGS $MSEED_CFLAGS"
	LDFLAGS="$LDFLAGS $MSEED_LIBS"
	AC_CHECK_HEADER(libmseed.h,
		AC_CHECK_LIB(mseed, msr_init,
			AC_DEFINE(HAVE_MSEED, 1, [Define if you have the mseed library]),
			[ if test "x$have_mseed" != xauto; then AC_MSG_ERROR([-lmseed library not found]); fi
			  have_mseed=no; why_have_mseed="(mseed library not found)" ], "-lm"),
		[ if test "x$have_mseed" != xauto; then AC_MSG_ERROR([libmseed.h header not found]); fi
		  have_mseed=no; why_have_mseed="(libmseed.h header not found)" ])
	LDFLAGS="$save_LDFLAGS"
	CPPFLAGS="$save_CPPFLAGS"
	if test "x$have_mseed" = "xyes" -o "x$have_mseed" = "xauto"; then
	    MSEED_CFLAGS=
	    MSEED_LIBS="-lmseed"
	fi
fi
AC_SUBST(MSEED_CFLAGS, $MSEED_CFLAGS)
AC_SUBST(MSEED_LIBS, $MSEED_LIBS)
AM_CONDITIONAL(HAVE_MSEED, test x"$have_mseed" != xno)

# samtools, only used by sql
org_have_samtools="auto"
have_samtools=$org_have_samtools
AC_ARG_WITH(samtools,
	AS_HELP_STRING([--with-samtools=DIR],
		[samtools (providing bam library) are installed in DIR]),
	[have_samtools="$withval"])
if test "x$have_samtools" != xno; then
	case "$have_samtools" in
	auto|yes)
		;;
	*)
		SAMTOOLS_CFLAGS="-I$have_samtools/include"
		SAMTOOLS_LIBS="-L$have_samtools/lib -lbam"
		;;
	esac

	save_CPPFLAGS="$CPPFLAGS"
	save_LDFLAGS="$LDFLAGS"
	CPPFLAGS="$CPPFLAGS $SAMTOOLS_CFLAGS"
	LDFLAGS="$LDFLAGS $SAMTOOLS_LIBS"

	AC_CHECK_HEADER(samtools/bam.h,
		[ why_have_samtools= ],
		[ why_have_samtools="samtools/bam.h header not found" ])
	if test -z "$why_have_samtools"; then
		AC_CHECK_HEADER(samtools/bgzf.h,
			[ why_have_samtools= ],
			[ why_have_samtools="samtools/bgzf.h header not found" ])
	fi
	if test -z "$why_have_samtools"; then
		AC_CHECK_LIB(bam, bam_header_read,
			AC_DEFINE(HAVE_SAMTOOLS, 1, [Define if you have the samtools (providing the bam library)]),
			[ why_have_samtools="bam library not found" ],
			[-lm -lpthread -lz])
	fi
	if test -n "$why_have_samtools"; then
		if test "x$have_samtools" != xauto; then
			AC_MSG_ERROR([$why_have_samtools])
		fi
		have_samtools=no
		why_have_samtools="($why_have_samtools)"
	fi
	LDFLAGS="$save_LDFLAGS"
	CPPFLAGS="$save_CPPFLAGS"
	if test "x$have_samtools" = "xyes" -o "x$have_samtools" = "xauto"; then
		SAMTOOLS_CFLAGS=
		SAMTOOLS_LIBS="-lbam"
		AC_CHECK_HEADERS([samtools/kstring.h])
	fi
fi
AC_SUBST(SAMTOOLS_CFLAGS, $SAMTOOLS_CFLAGS)
AC_SUBST(SAMTOOLS_LIBS, $SAMTOOLS_LIBS)
AM_CONDITIONAL(HAVE_SAMTOOLS, test x"$have_samtools" != xno)

# geos, only used in geom module
org_have_geos=auto
have_geos=$org_have_geos
GEOS_INCS=''
GEOS_LIBS=''
AC_ARG_WITH(geos,
	AS_HELP_STRING([--with-geos=DIR],
		[geos library is installed in DIR]),
	have_geos="$withval")
case "$enable_geom" in
yes|auto)
	GEOS_VERSION_REQUIRED_MIN=3.0.0
	GEOS_CONFIG=''
	if test "x$have_geos" != xno; then
		case "$have_geos" in
		yes|auto)
			XPATH="$PATH"
			;;
		*)
			XPATH="$have_geos/bin"
			have_geos=yes
			;;
		esac
		AC_PATH_PROG(GEOS_CONFIG,geos-config,,$XPATH)
		if test "x$GEOS_CONFIG" = x; then
			if test "x$have_geos" = "xyes" ; then
				AC_MSG_ERROR([geos-config not found in $XPATH])
			else
				have_geos=no
				why_have_geos="(geos-config not found)"
			fi
		fi
	fi
	if test "x$have_geos" != xno; then
		AC_MSG_CHECKING([for geos >= $GEOS_VERSION_REQUIRED_MIN])
		GEOS_VERSION="`$GEOS_CONFIG --version`"
		AC_MSG_RESULT(found $GEOS_VERSION)
		if test MONETDB_VERSION_TO_NUMBER(echo $GEOS_VERSION) -lt MONETDB_VERSION_TO_NUMBER(echo $GEOS_VERSION_REQUIRED_MIN); then
			if test "x$have_geos" = "xyes" ; then
				AC_MSG_ERROR([geos version $GEOS_VERSION is too old])
			else
				have_geos=no
				why_have_geos="(geos version $GEOS_VERSION is older than required version $GEOS_VERSION_REQUIRED_MIN)"
			fi
		fi
	fi
	if test "x$have_geos" != xno; then
		GEOS_INCS="`$GEOS_CONFIG --cflags`"
		if GEOS_LIBS="`$GEOS_CONFIG --clibs 2> /dev/null`"; then
			:
		else
			GEOS_LIBS="`$GEOS_CONFIG --libs | sed 's:-lgeos:-lgeos_c:'`"
		fi
	fi
	if test "x$have_geos" = xno; then
		if test "x$enable_geom" = xyes; then
			AC_MSG_ERROR([geos library required for geom module])
		fi
		# no geos, so don't compile geom
		enable_geom=no
		if test "x$disable_geom" = x; then
			disable_geom="(geos library required for geom module)"
		fi
	fi
	;;
esac
AC_SUBST(GEOS_INCS)
AC_SUBST(GEOS_LIBS)

org_have_cfitsio=no
have_cfitsio=$org_have_cfitsio
if test "x$enable_fits" != xno; then
	PKG_CHECK_MODULES([cfitsio], [cfitsio],
		[have_cfitsio=yes; AC_DEFINE(HAVE_CFITSIO, 1, [Define if you have the cfitsio library])],
		[have_cfitsio=no; why_have_cfitsio="(cfitsio library not found)"
		 if test "x$enable_fits" = xyes; then AC_MSG_ERROR([cfitsio library required for FITS support]); fi;
		 enable_fits=no; disable_fits="(cfitsio library not found)"])
fi
AM_CONDITIONAL(HAVE_CFITSIO, test x"$have_cfitsio" != xno)

PKG_CHECK_MODULES([atomic_ops], [atomic_ops], [have_atomic_ops="yes"],
	[have_atomic_ops="no"; why_have_atomic_ops="(atomic_ops library not found)"])
if test x"$have_atomic_ops" = x"yes" ; then
	case $GCC-$CC in
	-*icc*)
		# Even with libatomic_ops available, compilation with
		# atomic_ops enabled fails with Intel's icc (version 11.1);
		# hence, we refrain from from using atomic_ops with icc.
		have_atomic_ops="no"
		why_have_atomic_ops="(atomic_ops do not compile with Intel's icc)"
		;;
	*)
		# On some systems, notably OpenIndiana, atomic_ops may
		# seem to be installed in that there is a pkg-config
		# file for it, but that file contains incorrect
		# information, and can not, in fact, be used.  The
		# bogus pkg-config file for atomic_ops is part of the
		# library/gc package.
		save_CFLAGS="$CFLAGS"
		CFLAGS="$CFLAGS $atomic_ops_CFLAGS"
		AC_CHECK_HEADERS([atomic_ops.h],[have_atomic_ops=yes],[have_atomic_ops=no why_have_atomic_ops="(atomic_ops was incorrectly installed (happens on at least Solaris/OpenIndiana))"])
		CFAGS="$save_CFLAGS"
		if test x"$have_atomic_ops" = x"yes" ; then
			AC_DEFINE(HAVE_LIBATOMIC_OPS, 1, [Define if you have the libatomic_ops library])
			CFLAGS="$CFLAGS $atomic_ops_CFLAGS"
			LIBS="$LIBS $atomic_ops_LIBS"
		fi
		;;
	esac
fi

dnl MicroHTTPD library
dnl required for MonetDB5 SQL jsonstore, optional otherwise
org_have_libmicrohttpd=auto
have_libmicrohttpd=$org_have_libmicrohttpd
if test "x$enable_microhttpd" != xno; then
	PKG_CHECK_MODULES([libmicrohttpd], [libmicrohttpd],
		[have_libmicrohttpd=yes],
		[have_libmicrohttpd=no; why_have_libmicrohttpd="(libmicrohttpd not found)"; if test "x$enable_microhttpd" = xyes; then AC_MSG_ERROR([libmicrohttpd not found]); fi])
fi

org_have_liburiparser=auto
have_liburiparser=$org_have_liburiparser
if test "x$enable_jsonstore" != xno; then
	dnl Uriparser library
	dnl required for MonetDB5 SQL jsonstore, optional otherwise
	PKG_CHECK_MODULES([liburiparser], [liburiparser],
		[have_liburiparser=yes],
		[have_liburiparser=no; why_have_liburiparser="(liburiparser not found)"; if test "x$enable_jsonstore" = xyes; then AC_MSG_ERROR([LibUriParser library not found but required for jsonstore]); fi])

	if test "$have_libmicrohttpd-$have_liburiparser" = yes-yes; then
		AC_DEFINE(HAVE_JSONSTORE, 1, [Define that you want to build the jsonstore library])
	elif test "x$enable_jsonstore" = xyes; then
		AC_MSG_ERROR([cannot enable jsonstore $why_have_libmicrohttpd$why_have_liburiparser])
	fi
fi

dnl Check for gsl library for statistical functions
org_have_gsl=no
have_gsl=$org_have_gsl
if test "x$enable_gsl" != xno; then
	PKG_CHECK_MODULES([gsl], [gsl],
		[have_gsl=yes; AC_DEFINE(HAVE_GSL, 1, [Define if you have the gsl library])],
		[have_gsl=no; why_have_gsl="(gsl library not found)"
		 if test "x$enable_gsl" = xyes; then AC_MSG_ERROR([gsl library required for GSL support]); fi;
		 enable_gsl=no; disable_gsl="(gsl library not found)"])
fi
AM_CONDITIONAL(HAVE_GSL, test x"$have_gsl" != xno)

dnl     checks for header files
AC_HEADER_STDBOOL
AC_HEADER_STDC
AC_HEADER_TIME
AC_HEADER_DIRENT
# NOTE: these header files are in alphabetical order to ease maintenance
AC_CHECK_HEADERS([ \
	dlfcn.h \
	execinfo.h \
	fcntl.h \
	fenv.h \
	getopt.h \
	iconv.h \
	ieeefp.h \
	io.h \
	kvm.h \
	langinfo.h \
	libgen.h \
	libintl.h \
	limits.h \
	locale.h \
	mach-o/dyld.h \
	mach/mach_init.h \
	mach/task.h \
	malloc.h \
	netdb.h \
	netinet/in.h \
	procfs.h \
	pwd.h \
	regex.h \
	rlimit.h \
	signal.h \
	stddef.h \
	stdint.h \
	string.h \
	strings.h \
	stropts.h \
	sys/file.h \
	sys/ioctl.h \
	sys/mman.h \
	sys/param.h \
	sys/resource.h \
	sys/socket.h \
	sys/sysctl.h \
	sys/time.h \
	sys/times.h \
	sys/types.h \
	sys/uio.h \
	sys/un.h \
	sys/utime.h \
	sys/wait.h \
	termios.h \
	time.h \
	unistd.h \
	utime.h \
	uuid/uuid.h \
	winsock.h \
	xmmintrin.h \
	])

dnl on OpenBSD, sys/sysctl.h requires sys/param.h to be included beforehand
AC_CHECK_HEADERS([sys/sysctl.h], [], [],
[
  #ifdef HAVE_SYS_PARAM_H
  # include <sys/param.h>
  #endif
])


SOCKET_LIBS=""
org_have_setsockopt=no
have_setsockopt=$org_have_setsockopt
org_have_winsock2=no
have_winsock2=$org_have_winsock2

case "$host_os" in
	*mingw*)
		AC_CHECK_HEADERS([winsock2.h],[have_winsock2=yes],
			[have_winsock2=no; why_have_winsock2="(winsock2.h header not found)"])
		save_LIBS="$LIBS"
		LIBS="$LIBS -lws2_32"
		AC_MSG_CHECKING(for setsockopt in winsock2)
		AC_TRY_LINK([#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif],[setsockopt(0,0,0,NULL,0);],[SOCKET_LIBS="-lws2_32"; have_setsockopt=yes;],[])
		AC_MSG_RESULT($have_setsockopt)
		LIBS="$save_LIBS"
		;;
	*)
		AC_CHECK_FUNC(gethostbyname_r, [], [
		  AC_CHECK_LIB(nsl_r, gethostbyname_r, [ SOCKET_LIBS="-lnsl_r" ],
			AC_CHECK_LIB(nsl, gethostbyname_r, [ SOCKET_LIBS="-lnsl"   ] ))])
		AC_CHECK_FUNC(hstrerror, [], [
		  AC_CHECK_LIB(resolv, hstrerror, [ SOCKET_LIBS="$SOCKET_LIBS -lresolv" ])])
		;;
esac

if test "x$have_setsockopt" = xno; then
	AC_CHECK_FUNC(setsockopt, [], 
	  AC_CHECK_LIB(socket, setsockopt, [ SOCKET_LIBS="-lsocket $SOCKET_LIBS"; have_setsockopt=yes; ]))
fi

org_have_getaddrinfo=no
have_getaddrinfo=$org_have_getaddrinfo
save_LIBS="$LIBS"
LIBS="$LIBS $SOCKET_LIBS"

AC_CHECK_FUNC(getaddrinfo, [ have_getaddrinfo=yes ], [
  AC_CHECK_LIB(socket, getaddrinfo, [ SOCKET_LIBS="$SOCKET_LIBS -lsocket"; have_getaddrinfo=yes ],
	AC_CHECK_LIB(nsl,  getaddrinfo, [ SOCKET_LIBS="$SOCKET_LIBS -lnsl"   ; have_getaddrinfo=yes ] ))])
LIBS="$save_LIBS"

if test "x$have_getaddrinfo" = xyes; then
	AC_DEFINE([HAVE_GETADDRINFO], 1, [Define to 1 if you have the `getaddrinfo' function.])
fi

dnl incase of windows we need to use try_link because windows uses the
dnl pascal style of function calls and naming scheme. Therefore the 
dnl function needs to be compiled with the correct header
AC_CHECK_TYPE(SOCKET, , AC_DEFINE(SOCKET,int,[type used for sockets]), [#ifdef HAVE_WINSOCK_H
#include <winsock.h>
#endif])
AC_CHECK_TYPE(socklen_t,
	AC_DEFINE(HAVE_SOCKLEN_T, 1, [Define to 1 if the system has the type `socklen_t'.]),
	AC_DEFINE(socklen_t,int,[type used by connect]),
	[#include <sys/types.h>
#include <sys/socket.h>])

case $host_os in
	*mingw*)
		save_LIBS="$LIBS"
		LIBS="$LIBS $SOCKET_LIBS"
		AC_MSG_CHECKING(for closesocket)
		AC_TRY_LINK([#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif],[closesocket((SOCKET)0);], [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no);AC_DEFINE(closesocket,close,[function to close a socket])])
		LIBS="$save_LIBS"
		;;
	*)
		dnl don't check for closesocket on Cygwin: it'll be found but we don't want to use it
		AC_DEFINE(closesocket,close,[function to close a socket])
		;;
esac

AC_SUBST(SOCKET_LIBS)

dnl     checks for types
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_PID_T
AC_TYPE_OFF_T

AC_CHECK_TYPES([__int64, long long, __int128])
AC_CHECK_TYPES([ptrdiff_t],,,[#include <stddef.h>
#include <sys/types.h>])
dnl check for uintptr_t so that we can compile with rintegration on 32 bit arch
AC_CHECK_TYPES(uintptr_t)

AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(size_t)
AC_CHECK_SIZEOF(ssize_t)
AC_CHECK_SIZEOF(ptrdiff_t,,[#include <stddef.h>
#include <sys/types.h>])
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(__int64)
AC_C_CHAR_UNSIGNED

case $host_os in
	*mingw*)
		AC_DEFINE([LLFMT],["%I64d"],[Format to print 64 bit signed integers.])
		AC_DEFINE([ULLFMT],["%I64u"],[Format to print 64 bit unsigned integers.])
		;;
	*)
		AC_DEFINE([LLFMT],["%lld"],[Format to print 64 bit signed integers.])
		AC_DEFINE([ULLFMT],["%llu"],[Format to print 64 bit unsigned integers.])
		;;
esac

AC_TRY_COMPILE([$ac_includes_default
#include <malloc.h>], [struct mallinfo m;], AC_DEFINE(HAVE_STRUCT_MALLINFO, 1, [Define if you have struct mallinfo])

AC_TRY_COMPILE([$ac_includes_default
#include <malloc.h>], [struct mallinfo m = {0};
/* compilers that don't like <0 comparisons on unsigned data *
 * will fail here (but then not in src/gdk/gdk_utils.c)     */
int x = (m.usmblks < 0);], AC_DEFINE(HAVE_SIGNED_MALLINFO, 1, [Define if your mallinfo struct has signed elements])
))

dnl     checks for structures
dnl     checks for compiler characteristics
AC_C_CONST
AC_C_INLINE
AC_COMPILE_IFELSE([AC_LANG_SOURCE([int foo(int * restrict p) { return *p; }])],
	AC_DEFINE(HAVE_RESTRICT, 1,
		[Define if the compiler supports the restrict keyword]),
	AC_COMPILE_IFELSE([AC_LANG_SOURCE([int foo(int * __restrict__ p) { return *p; }])],
		AC_DEFINE(HAVE___RESTRICT__, 1,
			[Define if the compiler supports the __restrict__ keyword])))

dnl Seems like the compiler on SunOS 5.8 cannot cope with the
dnl __attribute__ specifications that can give compilers additional
dnl hints about a function (style of variable argument list, functions
dnl that never return, etc.)
AC_MSG_CHECKING([if your compiler understands `__attribute__'])

save_CFLAGS="$CFLAGS"
case "$GCC-$CC-$host_os" in
-*-solaris*)
	dnl  Sun compiler on Solaris:
	dnl  treat warnings as errors to fail on
	dnl  'warning: attribute parameter "printf" is undefined'
	CFLAGS="$CFLAGS -errwarn=%all"
	;;
esac

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdlib.h>

static void foo (const char *a, ...)
	__attribute__ ((format (printf, 1, 2)));

static void foo (const char *a, ...)
	{ (void)a; }
]],
[[ foo ("%s", ""); ]]
)],
[AC_DEFINE([HAVE_FUNCTION_ATTRIBUTES], 1,
  [Does your compiler support function attributes (__attribute__)?])
AC_MSG_RESULT(yes)],
AC_MSG_RESULT(no))

CFLAGS="$save_CFLAGS"

AH_VERBATIM([__attribute__],
[/* If the compiler does not support function attributes via __attribute__,
   we just define __attribute__(a) to nothing. */
#ifndef HAVE_FUNCTION_ATTRIBUTES
#define __attribute__(a)
#endif
])

dnl     checks for library functions
case $host in
	*-darwin1[[01234]]*)
		# OSX 10.6 (Snow Leopard) and up somehow makes configure believe
		# that fdatasync exists, in reality however, it does not on this
		# platform.
		ac_cv_func_fdatasync=no
	;;
	*)
		AC_CHECK_FUNCS([fdatasync])
	;;
esac
AS_IF([test "x${ac_cv_func_fdatasync}" = "xyes"],
  [AC_DEFINE([HAVE_FDATASYNC],[1],[If the system has a working fdatasync])])

AC_FUNC_ALLOCA
AC_FUNC_FSEEKO
# NOTE: these functions are in alphabetical order to ease maintenance
save_LIBS="$LIBS"
LIBS="$LIBS $MATH_LIBS"
AC_CHECK_FUNCS([\
				asctime_r \
				backtrace \
				ctime_r \
				fabsf \
				fcntl \
				fpclass \
				fpclassify \
				fsync \
				ftime \
				getexecname \
				getlogin \
				getopt \
				getopt_long \
				GetSystemInfo \
				gettimeofday \
				getuid \
				isinf \
				kill \
				llabs \
				localtime_r \
				lockf \
				madvise \
				mremap \
				nl_langinfo \
				_NSGetExecutablePath \
				pipe \
				popen \
				posix_fadvise \
				posix_fallocate \
				posix_madvise \
				putenv \
				round \
				sbrk \
				setenv \
				setlocale \
				setsid \
				shutdown \
				sigaction \
				strcasestr \
				strftime \
				strncasecmp \
				strptime \
				strsignal \
				strtod \
				strtof \
				strtoll \
				strtoull \
				sysconf \
				task_info \
				times \
				trunc \
				uname \
				])
LIBS="$save_LIBS"

dnl check for getopt in standard library
AC_CHECK_HEADERS([getopt.h])
AC_CHECK_FUNCS(getopt_long , need_getopt=, need_getopt=getopt; need_getopt=getopt1)
if test x$need_getopt = xgetopt; then
	AC_LIBOBJ(getopt)
elif test x$need_getopt = xgetopt1; then
	AC_LIBOBJ(getopt1)
fi

asctime_r3=yes
AC_MSG_CHECKING(asctime_r3)
AC_TRY_LINK([$ac_includes_default
#include <time.h>],
[char buf[26]; struct tm t; asctime_r(&t,buf,26);],
[AC_DEFINE(HAVE_ASCTIME_R3, 1, [Define if you have asctime_r(struct tm*,char *buf,size_t s)])], [asctime_r3=no])
AC_MSG_RESULT($asctime_r3)

ctime_r3=yes
AC_MSG_CHECKING(ctime_r3)
AC_TRY_LINK([$ac_includes_default
#include <time.h>],
[char buf[26]; time_t t; ctime_r(&t,buf,26);],
[AC_DEFINE(HAVE_CTIME_R3, 1, [Define if you have ctime_r(time_t*,char *buf,size_t s)])], [ctime_r3=no])
AC_MSG_RESULT($ctime_r3)

AC_CACHE_CHECK(for _sys_siglist, mn_cv_have__sys_siglist, [
AC_TRY_LINK([$ac_includes_default], [printf("%s\n", _sys_siglist[0]);], mn_cv_have__sys_siglist=yes, mn_cv_have__sys_siglist=no)])
if test $mn_cv_have__sys_siglist = yes; then
	AC_DEFINE(HAVE__SYS_SIGLIST, 1, [Define if you have _sys_siglist])
fi

dnl     checks for system services
dnl hwcounters
org_have_hwcounters=auto
have_hwcounters=$org_have_hwcounters
HWCOUNTERS_LIBS=""
HWCOUNTERS_INCS=""
AC_ARG_WITH(hwcounters,
	AS_HELP_STRING([--with-hwcounters=DIR],
		[hwcounters library is installed in DIR]),
	have_hwcounters="$withval")
case "$have_hwcounters" in
yes|no|auto)
	;;
*)
	HWCOUNTERS_LIBS="-L$withval/lib"
	HWCOUNTERS_INCS="-I$withval/include"
	;;
esac
if test "x$have_hwcounters" != xno; then
	case "$host_os-$host" in
	linux*-i?86*) HWCOUNTERS_INCS="$HWCOUNTERS_INCS -I/usr/src/linux-`uname -r | sed 's|smp$||'`/include"
	esac
	save_CPPFLAGS="$CPPFLAGS"
	CPPFLAGS="$CPPFLAGS $HWCOUNTERS_INCS"
	save_LIBS="$LIBS"
	LIBS="$LIBS $HWCOUNTERS_LIBS"
	have_hwcounters=no
	why_have_hwcounters="(no supported harwdware counters interface found)"
	case "$host_os-$host" in
	linux*-i?86*|linux*-x86_64*)
		AC_CHECK_HEADERS( libperfctr.h ,
		 AC_CHECK_LIB( perfctr, vperfctr_open ,
		  [ HWCOUNTERS_LIBS="$HWCOUNTERS_LIBS -lperfctr"
			AC_DEFINE(HAVE_LIBPERFCTR, 1, [Define if you have the perfctr library])
			have_hwcounters=yes
		  ]
			 )
		)
		if test "x$have_hwcounters" != xyes; then
				AC_CHECK_HEADERS( libpperf.h,
			 AC_CHECK_LIB( pperf, start_counters,
			  [ HWCOUNTERS_LIBS="$HWCOUNTERS_LIBS -lpperf"
					AC_DEFINE(HAVE_LIBPPERF, 1, [Define if you have the pperf library])
					have_hwcounters=yes
			  ]
			 )
			)
		fi
		;;
	 linux*-ia64*)
		AC_CHECK_HEADERS( perfmon/pfmlib.h ,
		 AC_CHECK_LIB( pfm, pfm_initialize ,
		  [ HWCOUNTERS_LIBS="$HWCOUNTERS_LIBS -lpfm"
			AC_DEFINE(HAVE_LIBPFM, 1, [Define if you have the pfm library])
			have_hwcounters=yes
		  ]
			 )
		)
		;;
	 solaris*)
		AC_CHECK_HEADERS( libcpc.h ,
		 AC_CHECK_TYPE( cpc_event_t,
		  AC_CHECK_LIB( cpc, cpc_access ,
		   [ HWCOUNTERS_LIBS="$HWCOUNTERS_LIBS -lcpc"
			 AC_DEFINE(HAVE_LIBCPC, 1, [Define if you have the cpc library])
			 have_hwcounters=yes
		   ]
		  )
		  , , [#include <libcpc.h>]
		 )
		)
		if test "x$have_hwcounters" != xyes; then
			AC_CHECK_HEADERS( perfmon.h ,
			 AC_CHECK_LIB( perfmon, clr_pic ,
			  [ HWCOUNTERS_LIBS="$HWCOUNTERS_LIBS -lperfmon"
				AC_DEFINE(HAVE_LIBPERFMON, 1, [Define if you have the perfmon library])
				have_hwcounters=yes
			  ]
			 )
			)
		fi
		;;
	 irix*)
		AC_CHECK_LIB( perfex, start_counters ,
		 [ HWCOUNTERS_LIBS="$HWCOUNTERS_LIBS -lperfex"
		   have_hwcounters=yes
		 ]
		)
		;;
	esac
	LIBS="$save_LIBS"
	CPPFLAGS="$save_CPPFLAGS"

	if test "x$have_hwcounters" != xyes; then
		HWCOUNTERS_LIBS=""
		HWCOUNTERS_INCS=""
	else
		CFLAGS="$CFLAGS -DHWCOUNTERS -DHW_`uname -s` -DHW_`uname -m`"
	fi
fi
AC_SUBST(HWCOUNTERS_LIBS)
AC_SUBST(HWCOUNTERS_INCS)

dnl check dependencies (might need more than just SQL)
if test x"$enable_sql" = xyes && test x"$enable_monetdb5" = x"no" ; then
	AC_MSG_ERROR([MonetDB/SQL requires MonetDB5${disable_monetdb5:+ $disable_monetdb5}.])
fi
if test x"$enable_sql" = xauto && test x"$enable_monetdb5" = x"no" ; then
	enable_sql=no
	if test "x$disable_sql" = x; then
		disable_sql="(MonetDB/SQL requires MonetDB5)"
	fi
fi

dnl     output
AM_CONDITIONAL(HAVE_GDK, test "x$enable_gdk" = xyes -o "x$enable_gdk" = xauto)
AM_CONDITIONAL(HAVE_MONETDB5, test "x$enable_monetdb5" = xyes -o "x$enable_monetdb5" = xauto)
AM_CONDITIONAL(HAVE_SQL, test "x$enable_sql" = xyes -o "x$enable_sql" = xauto)
AM_CONDITIONAL(HAVE_GEOM, test "x$enable_geom" = xyes -o "x$enable_geom" = xauto)
AM_CONDITIONAL(HAVE_JSONSTORE, test "x$enable_jsonstore" = xyes -o "x$enable_jsonstore" = xauto)
AM_CONDITIONAL(HAVE_TESTING, test "x$enable_testing" = xyes -o "x$enable_testing" = xauto)
AM_CONDITIONAL(HAVE_DEVELOPER, test "x$enable_developer" = xyes)

AC_SUBST(compilercall, ["$CC $CFLAGS $X_CFLAGS"])
AC_SUBST(linkercall, ["$LD $LDFLAGS"])
AC_SUBST(builtby, ["${USER}@`hostname`"])
pcreversion="not linked to any PCRE library"
if test "x$have_pcre" = xyes; then
        pcreversion="compiled with `pkg-config --modversion libpcre 2>/dev/null`"
fi
AC_SUBST(pcreversion)
opensslversion="not linked to any openssl library"
if test "x$have_openssl" = xyes; then
        opensslversion="compiled with `openssl version 2>/dev/null`"
fi
AC_SUBST(opensslversion)
libxml2version="not linked to any libxml2 library"
if test "x$have_libxml2" = xyes; then
        libxml2version="compiled with `pkg-config --modversion libxml-2.0 2>/dev/null`"
fi
AC_SUBST(libxml2version)

dnl provide different versions of the paths derived above
if test "${prefix}x" = "NONEx"; then
	prefix="${ac_default_prefix}"
	Xprefix="`$translatepath "$Qprefix"`"
	QXprefix="`echo "$Xprefix" | sed 's/\\\\/\\\\\\\\/g'`"
else
	Xprefix="`$translatepath "$prefix"`"
	QXprefix="`echo "$Xprefix" | sed 's/\\\\/\\\\\\\\/g'`"
fi
if test "${exec_prefix}x" = "NONEx"; then
	Xexec_prefix="`$translatepath "$Qexec_prefix"`"
	QXexec_prefix="`echo "$Xexec_prefix" | sed 's/\\\\/\\\\\\\\/g'`"
else
	Xexec_prefix="`$translatepath "$exec_prefix"`"
	QXexec_prefix="`echo "$Xexec_prefix" | sed 's/\\\\/\\\\\\\\/g'`"
fi
AC_SUBST(Xprefix)
AC_SUBST(QXprefix)
AC_SUBST(Xexec_prefix)
AC_SUBST(QXexec_prefix)
Qsrcdir="$srcdir"
Xsrcdir="`$translatepath "$srcdir"`"
QXsrcdir="`echo "$Xsrcdir" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(Qsrcdir)
AC_SUBST(Xsrcdir)
AC_SUBST(QXsrcdir)
Qlocalstatedir="$localstatedir"
Xlocalstatedir="`$translatepath "$localstatedir"`"
QXlocalstatedir="`echo "$Xlocalstatedir" | sed 's/\\\\/\\\\\\\\/g'`"
eval "Elocalstatedir=${Xlocalstatedir}"
QElocalstatedir="`echo "$Elocalstatedir" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(Qlocalstatedir)
AC_SUBST(Xlocalstatedir)
AC_SUBST(Elocalstatedir)
AC_SUBST(QXlocalstatedir)
Xlogdir="`$translatepath "$logdir"`"
eval "Elogdir=${Xlogdir}"
# need second eval because localstatedir defaults to being ${prefix}/var
eval "Elogdir=${Elogdir}"
AC_SUBST(logdir)
AC_SUBST(Elogdir)
Xrundir="`$translatepath "$rundir"`"
eval "Erundir=${Xrundir}"
# need second eval because localstatedir defaults to being ${prefix}/var
eval "Erundir=${Erundir}"
AC_SUBST(rundir)
AC_SUBST(Erundir)
Qlibdir="$libdir"
Xlibdir="`$translatepath "$libdir"`"
QXlibdir="`echo "$Xlibdir" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(Qlibdir)
AC_SUBST(Xlibdir)
AC_SUBST(QXlibdir)
Qsysconfdir="$sysconfdir"
Xsysconfdir="`$translatepath "$sysconfdir"`"
QXsysconfdir="`echo "$Xsysconfdir" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(Qsysconfdir)
AC_SUBST(Xsysconfdir)
AC_SUBST(QXsysconfdir)
Qbindir="$bindir"
Xbindir="`$translatepath "$bindir"`"
QXbindir="`echo "$Xbindir" | sed 's/\\\\/\\\\\\\\/g'`"
Ebindir="`echo "$Xbindir" | sed 's/{exec_prefix}/{prefix}/'`"
eval "Ebindir=${Ebindir}"
QEbindir="`echo "$Ebindir" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(Qbindir)
AC_SUBST(Xbindir)
AC_SUBST(QXbindir)
Qlibexecdir="$libexecdir"
Xlibexecdir="`$translatepath "$libexecdir"`"
QXlibexecdir="`echo "$Xlibexecdir" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(Qlibexecdir)
AC_SUBST(Xlibexecdir)
AC_SUBST(QXlibexecdir)
Qdatarootdir="$datarootdir"
Xdatarootdir="`$translatepath "$datarootdir"`"
QXdatarootdir="`echo "$Xdatarootdir" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(Qdatarootdir)
AC_SUBST(Xdatarootdir)
AC_SUBST(QXdatarootdir)
if test "${datadir}" = '${datarootdir}'; then
	datadir="${datarootdir}"
fi
Qdatadir="$datadir"
Xdatadir="`$translatepath "$datadir"`"
QXdatadir="`echo "$Xdatadir" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(Qdatadir)
AC_SUBST(Xdatadir)
AC_SUBST(QXdatadir)
Qmandir="$mandir"
Xmandir="`$translatepath "$mandir"`"
QXmandir="`echo "$Xmandir" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(Qmandir)
AC_SUBST(Xmandir)
AC_SUBST(QXmandir)
Qincludedir="$includedir"
Xincludedir="`$translatepath "$includedir"`"
QXincludedir="`echo "$Xincludedir" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(Qincludedir)
AC_SUBST(Xincludedir)
AC_SUBST(QXincludedir)
Qinfodir="$infodir"
Xinfodir="`$translatepath "$infodir"`"
QXinfodir="`echo "$Xinfodir" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(Qinfodir)
AC_SUBST(Xinfodir)
AC_SUBST(QXinfodir)

QBUILD="$BUILD"
XBUILD="`$translatepath "$BUILD"`"
QXBUILD="`echo "$XBUILD" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(QBUILD)
AC_SUBST(XBUILD)
AC_SUBST(QXBUILD)
QSOURCE="$SOURCE"
XSOURCE="`$translatepath "$SOURCE"`"
QXSOURCE="`echo "$XSOURCE" | sed 's/\\\\/\\\\\\\\/g'`"
AC_SUBST(QSOURCE)
AC_SUBST(XSOURCE)
AC_SUBST(QXSOURCE)
AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$QElocalstatedir",[modifiable single-machine data])
AC_DEFINE_UNQUOTED(BINDIR,"$QEbindir",[location where binaries are installed])

dnl  On Solaris, libxml2 enables threading only when _REENTRANT, __MT__
dnl  or _POSIX_C_SOURCE >= 199506L is defined.  The latter is only
dnl  defined on POSIX compliant Solaris systems (latest of the latest
dnl  as of this writing), hence defining that here would cause a
dnl  redefinition error.  To work around it, we define __MT__ here, as
dnl  _REENTRANT might also enable stuff in other software packages.
case "$GCC-$host_os" in
yes-solaris2.11)
	AC_DEFINE(__MT__, 1, [libxml2 enable threading compiler flag])
	;;
esac

dnl add some includes that we want to be there always (by default)
dnl this is kind of bad practice, but consider it legacy that would be
dnl good to clean up some day
AH_TOP([
#ifndef _SEEN_MONETDB_CONFIG_H
#define _SEEN_MONETDB_CONFIG_H 1
])
AH_BOTTOM([
/* AC_FUNC_ALLOCA autoconf documented code */
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#elif defined __GNUC__
# define alloca __builtin_alloca
#elif defined _AIX
# define alloca __alloca
#elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
#else
# include <stddef.h>
void *alloca(size_t);
#endif

#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif

#include <stdio.h>		/* NULL, printf etc. */
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>		/* va_alist.. */
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#ifndef HAVE_UINTPTR_T
typedef size_t uintptr_t;
#endif
#ifdef HAVE_STDBOOL_H
#include <stdbool.h>
#endif
#ifndef __bool_true_false_are_defined
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
#endif

#include <assert.h>

#define SLASH_2_DIR_SEP(s) {char *t; for(t=strchr(s, '/'    ); t; t=strchr(t+1, '/'    )) *t=DIR_SEP;}
#define DIR_SEP_2_SLASH(s) {char *t; for(t=strchr(s, DIR_SEP); t; t=strchr(t+1, DIR_SEP)) *t='/'    ;}

#ifdef HAVE_LONG_LONG
typedef long long lng;
# define SIZEOF_LNG SIZEOF_LONG_LONG
#else
# ifdef HAVE___INT64
typedef __int64 lng;
#  define SIZEOF_LNG SIZEOF___INT64
# endif
#endif

#ifndef HAVE_PTRDIFF_T
# if SIZEOF_SIZE_T == SIZEOF_INT
typedef int ptrdiff_t;
# else
typedef lng ptrdiff_t;
# endif
#endif

/* define printf formats for printing size_t and ssize_t variables */
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901 && !defined(__svr4__) && !defined(WIN32) && !defined(__sgi)) || __GNUC__ > 3
# define SZFMT "%zu"
# define SSZFMT "%zd"
#elif defined(__MINGW32__)
# define SZFMT "%u"
# define SSZFMT "%ld"
#elif SIZEOF_SIZE_T == SIZEOF_INT
# define SZFMT "%u"
# define SSZFMT "%d"
#elif SIZEOF_SIZE_T == SIZEOF_LONG
# define SZFMT "%lu"
# define SSZFMT "%ld"
#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG || SIZEOF_SIZE_T == SIZEOF___INT64
# define SZFMT ULLFMT
# define SSZFMT LLFMT
#else
# error no definition for SZFMT/SSZFMT
#endif

/* define printf formats for printing ptrdiff_t variables */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901 && !defined(__svr4__) && !defined(WIN32) && !defined(__sgi) || defined(__hpux)
#define PDFMT "%td"
#elif SIZEOF_PTRDIFF_T == SIZEOF_INT
#define PDFMT "%d"
#elif SIZEOF_PTRDIFF_T == SIZEOF_LONG
#define PDFMT "%ld"
#elif SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG || SIZEOF_PTRDIFF_T == SIZEOF___INT64
#define PDFMT LLFMT
#else
#error no definition for PDFMT
#endif

/* define printf format for printing pointer values */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901
#define PTRFMT		"%p"
#define PTRFMTCAST		/* no cast needed */
#elif defined(_MSC_VER)
#define PTRFMT		"%p"
#define PTRFMTCAST
#elif SIZEOF_VOID_P == SIZEOF_INT
#define PTRFMT		"%x"
#define PTRFMTCAST	(unsigned int)
#elif SIZEOF_VOID_P == SIZEOF_LONG
#define PTRFMT		"%lx"
#define PTRFMTCAST	(unsigned long)
#elif SIZEOF_VOID_P == SIZEOF_LONG_LONG
#define PTRFMT		"%llx"
#define PTRFMTCAST	(unsigned long long)
#else
#error no definition for PTRFMT
#endif

/* defines to help the compiler check printf-style format arguments */
#if !defined(__GNUC__) || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
/* This feature is available in gcc versions 2.5 and later.  */
# ifndef __attribute__
#  define __attribute__(Spec) /* empty */
# endif
#else
/* The __-protected variants of `format' and `printf' attributes are
 * accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
# if !defined(__format__) && (__GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7))
#  define __format__ format
#  define __printf__ printf
# endif
#endif
#if !defined(_MSC_VER) && !defined(_In_z_)
# define _In_z_
# define _Printf_format_string_
# define __declspec(x)
#endif

#endif /* _SEEN_MONETDB_CONFIG_H */
])

dnl  Disabling the following warning is only required for the Intel compiler
dnl  and if assertions are enabled.
case "$GCC-$CC-$enable_assert" in
-*icc*-yes|-*ecc*-yes)
	dnl  # 279: controlling expression is constant
	X_CFLAGS="$X_CFLAGS -wd279";;
esac

dnl  CFLAGS for our code are stricter than what autoconf can cope with.
CFLAGS="$CFLAGS \$(X_CFLAGS)"

dnl bootstrap adds a (long) list of file names inside the
dnl AC_CONFIG_FILES command
AC_CONFIG_FILES([
Makefile
buildtools/Makefile
common/Makefile
clients/Makefile
gdk/Makefile
common/stream/Makefile
common/options/Makefile
common/utils/Makefile
clients/mapilib/Makefile
clients/mapiclient/Makefile
])
AC_CONFIG_FILES([rpm.mk], [chmod +x rpm.mk])
AC_CONFIG_FILES([gdk/monetdb-gdk.pc], [chmod +x gdk/monetdb-gdk.pc])
AC_CONFIG_FILES([monetdb5/Makefile], [chmod +x monetdb5/Makefile])
AC_CONFIG_FILES([sql/Makefile], [chmod +x sql/Makefile])
AC_CONFIG_FILES([tools/Makefile], [chmod +x tools/Makefile])
AC_CONFIG_FILES([buildtools/conf/Makefile], [chmod +x buildtools/conf/Makefile])
AC_CONFIG_FILES([common/stream/monetdb-stream.pc], [chmod +x common/stream/monetdb-stream.pc])
AC_CONFIG_FILES([clients/mapilib/monetdb-mapi.pc], [chmod +x clients/mapilib/monetdb-mapi.pc])
AC_CONFIG_FILES([monetdb5/mal/Makefile], [chmod +x monetdb5/mal/Makefile])
AC_CONFIG_FILES([monetdb5/modules/Makefile], [chmod +x monetdb5/modules/Makefile])
AC_CONFIG_FILES([monetdb5/optimizer/Makefile], [chmod +x monetdb5/optimizer/Makefile])
AC_CONFIG_FILES([monetdb5/scheduler/Makefile], [chmod +x monetdb5/scheduler/Makefile])
AC_CONFIG_FILES([monetdb5/tools/Makefile], [chmod +x monetdb5/tools/Makefile])
AC_CONFIG_FILES([monetdb5/tools/monetdb5.pc], [chmod +x monetdb5/tools/monetdb5.pc])
AC_CONFIG_FILES([monetdb5/NT/Makefile], [chmod +x monetdb5/NT/Makefile])
AC_CONFIG_FILES([sql/include/Makefile], [chmod +x sql/include/Makefile])
AC_CONFIG_FILES([sql/common/Makefile], [chmod +x sql/common/Makefile])
AC_CONFIG_FILES([sql/storage/Makefile], [chmod +x sql/storage/Makefile])
AC_CONFIG_FILES([sql/server/Makefile], [chmod +x sql/server/Makefile])
AC_CONFIG_FILES([sql/backends/Makefile], [chmod +x sql/backends/Makefile])
AC_CONFIG_FILES([sql/scripts/Makefile], [chmod +x sql/scripts/Makefile])
AC_CONFIG_FILES([sql/NT/Makefile], [chmod +x sql/NT/Makefile])
AC_CONFIG_FILES([tools/mserver/Makefile], [chmod +x tools/mserver/Makefile])
AC_CONFIG_FILES([tools/mserver/monet_version.c], [chmod +x tools/mserver/monet_version.c])
AC_CONFIG_FILES([tools/mserver/mserver5.1], [chmod +x tools/mserver/mserver5.1])
AC_CONFIG_FILES([tools/merovingian/Makefile], [chmod +x tools/merovingian/Makefile])
AC_CONFIG_FILES([monetdb5/modules/atoms/Makefile], [chmod +x monetdb5/modules/atoms/Makefile])
AC_CONFIG_FILES([monetdb5/modules/kernel/Makefile], [chmod +x monetdb5/modules/kernel/Makefile])
AC_CONFIG_FILES([monetdb5/modules/mal/Makefile], [chmod +x monetdb5/modules/mal/Makefile])
AC_CONFIG_FILES([sql/storage/bat/Makefile], [chmod +x sql/storage/bat/Makefile])
AC_CONFIG_FILES([sql/backends/monet5/Makefile], [chmod +x sql/backends/monet5/Makefile])
AC_CONFIG_FILES([tools/merovingian/utils/Makefile], [chmod +x tools/merovingian/utils/Makefile])
AC_CONFIG_FILES([tools/merovingian/client/Makefile], [chmod +x tools/merovingian/client/Makefile])
AC_CONFIG_FILES([tools/merovingian/daemon/Makefile], [chmod +x tools/merovingian/daemon/Makefile])
AC_CONFIG_FILES([tools/merovingian/daemon/monetdbd.1], [chmod +x tools/merovingian/daemon/monetdbd.1])
AC_CONFIG_FILES([tools/merovingian/daemon/.merovingian_properties], [chmod +x tools/merovingian/daemon/.merovingian_properties])
AC_OUTPUT

echo
echo
echo "MonetDB is configured as follows:"
echo "* Compilation specifics:"
echo "    Host:     " ${ac_cv_host}
echo "    Compiler: " ${CC} "("${CC_ver}"; "${CC_version}")"
echo "    CFLAGS:   " ${CFLAGS}
echo "    X_CFLAGS: " ${X_CFLAGS}
echo "    LDFLAGS:  " ${LDFLAGS}
echo
echo "* Enabled/disabled build options:"
for comp in \
	'strict    ' \
	'assert    ' \
	'debug     ' \
	'optimize  ' \
	'developer ' \
	'instrument' \
	'profile   ' \
; do
	eval "dft=\$dft_$comp"
	eval "enable=\$enable_$comp"
	eval "disable=\$disable_$comp"
	case "$disable-$enable-$dft" in
		-no-no)	disable="(by default)";;
		-no-*)	disable="(by command line option)";;
	esac
	echo $ECHO_N "    $comp is $ECHO_C"
	if test "x$enable" = xno ; then echo "disabled $disable"; else echo "enabled"; fi
done
echo
echo "* Enabled/disabled components:"
for comp in \
	'gdk         ' \
	'monetdb5    ' \
	'sql         ' \
	'geom        ' \
	'gsl         ' \
	'fits        ' \
	'jsonstore   ' \
	'microhttpd  ' \
	'rdf         ' \
	'rintegration' \
	'datacell    ' \
	'odbc        ' \
	'jdbc        ' \
	'control     ' \
	'testing     ' \
; do
	eval "dft=\$dft_$comp"
	eval "enable=\$enable_$comp"
	eval "disable=\$disable_$comp"
	case "$disable-$enable-$dft" in
		-no-no)	disable="(by default)";;
		-no-*)	disable="(by command line option)";;
	esac
	echo $ECHO_N "    $comp is $ECHO_C"
	if test "x$enable" = xno ; then echo "disabled $disable"; else echo "enabled"; fi
done
echo
echo "* Available features/extensions:"
for comp in \
	'atomic_ops   ' \
	'bz2          ' \
	'cfitsio      ' \
	'curl         ' \
	'geos         ' \
	'getaddrinfo  ' \
	'gsl          ' \
	'hwcounters   ' \
	'java         ' \
	'java_control ' \
	'java_jdbc    ' \
	'libmicrohttpd' \
	'liburiparser ' \
	'libxml2      ' \
	'mseed        ' \
	'openssl      ' \
	'pcre         ' \
	'perl         ' \
	'pthread      ' \
	'python2      ' \
	'python3      ' \
	'raptor       ' \
	'readline     ' \
	'rubygem      ' \
	'samtools     ' \
	'setsockopt   ' \
	'sphinxclient ' \
	'unixodbc     ' \
	'valgrind     ' \
	'winsock2     ' \
	'zlib         ' \
; do
	eval "org=\$org_have_$comp"
	eval "have=\$have_$comp"
	eval "why=\$why_have_$comp"
	case "$why-$have-$org" in
		-no-no)	why="(by default)";;
		-no-*)	why="(by command line option)";;
	esac
	echo $ECHO_N "    $comp = $ECHO_C"
	if test "x$have" != xno ; then echo "yes"; else echo "no  $why"; fi
done
echo
echo "* Important options:"
echo "    OID size: " ${oids} bits
echo

dnl give some hints to the user
case "`make -v 2>&1`" in
'GNU Make '*)
	;;
*)
	echo "'make' not found in PATH or not GNU Make."
	case "`gmake -v 2>&1`" in
	'GNU Make '*)
		echo "Please use 'gmake' to build MonetDB."
		;;
	*)
		echo "'gmake' not found in PATH or not GNU Make."
		echo "Please make sure you have GNU Make installed and use it to build MonetDB."
		;;
	esac
	echo
	;;
esac
